android_guides
android_guides copied to clipboard
Will context.getApplicationContext return null happen?
According to this page Understanding the Android Application Class
The application object is not guaranteed to stay in memory forever
So the application will be released when somes components is alive? My app has some crash reports caused by application null pointer exception in service.
Can you show those crashes?
Possible in theory bizarre in practicality.
Yes it will some times. We faced the same issue. You should use context.getApplicatinContext when it requires to place some thing global level. You can use them for things like toast etc but not for creating UI etc.
Can you show those crashes?
It happened on a few devices. I can't reproduce.
Services are running in a different sandbox from the app, having a service running doesn't guarantee keeping the app alive. You might have to change your approach of "setting things globally" -> Broadcast, sharedpreferences ...Etc
Careful when using getApplicationContext
as it would cause memory leak when using it with long living object. Try some other contexts as described here