I'm writing an android app, and I have a little p开发者_C百科roblem regarding Context.
I've read the Avoiding Memory Leaks article on Android developers. They suggest using application context instead of activity context to avoid memory leaks.
The problem is when I do that, my app crashes on several places(using Nexus S, although I heard this issue occurs is other phones as well).
So I have 2 questions-
Is anyone familiar with this issue?
In general, what context should I use? If my app is written using activity context, and it works fine, should I now try to rewrite it to use application context?
Don't use the application just because you want to avoid memory leaks. Don't use it unless you actually know why you are using it. Only use it, as the article says, if you are creating objects that live separately from the activity. These things by definition should not be doing things that rely on the kinds of things associated with an activity -- showing dialogs, etc.
精彩评论