Hello, 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 previous 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.
A:
When you are 'ending' your activity it is just going in background. So state will be maintained. If you want to do something when the activity is not 'visible' you have to implement the onStop()
method and not onDestroy()
.
Please refer how android manages stack of Tasks and activities. Also refer Activity Lifecycle.
Activity is stopped if it is completely obscured by another activity. It still retains all state and member information. However, it is no longer visible to the user so its window is hidden and it will often be killed by the system when memory is needed elsewhere.
Gopi
2010-08-05 08:20:04
thank you, this information I was just missing
2010-08-09 16:54:49