I get a NullPointerException in my onCreate method in some activities. It’s hard to debug because it happens only after a long time of idleness.
It’s probably because the activity has ended and the garbage collector has destroyed some shared objects but I’m not sure.
What should I do to handle that in a proper way ?
Thank’s
Activities do not “end” after a period of idleness, and they do not get reclaimed by the garbage collector. What happens is that the operating system kills your whole process. Then, when the user returns to the activity, the operating system recreates the process and recreates only the top activity on the activity stack. So if you have any static (class) variables that may have been set up by other activities, all those things are long gone.
Post the code in your
onCreate()and indicate where the NullPointerException happened (look at your logcat).