开发者

living singleton, when activity end

I have a singleton in an activity. When I end my application (like pressing back button), and start it again after some time, the singleton is not recreated, but is holding pre开发者_如何学编程vious state. Singleton is not destroyed if the application is destroyed? Do I have to null its static members in onDestroy() to avoid memory leak? Thanks.


Take a look at the attached picture.

Just because the application is no longer visible doesn't mean it has shut down.

I'd have to see code to give you a definitive answer, but before you assume the application is gone, kill the application manually with a task killer or the built-in application manager. Then, see if when you restart it, the singleton is reinitialized.

If killing it manually fixes the problem, you may want to 'uninitialize' the singleton in "onStop()" if you want it to go away when the application leaves the foreground. You can also try adding an "exit" menu function?

If you give me an update either with code or whether the task killer works, I'll see if I can give you a better answer.

(sorry I can't just attach the picture--I'm a new user) http://developer.android.com/images/activity_lifecycle.png

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜