Reputation: 6128
i have a Object obj where i need to save the state of this object for long time, so if i extend application class what is the Lifetime of it?
When the user in the current activity and gets a call, after long time the user resumes the activity what will happen to my object and the activity?
Upvotes: 0
Views: 579
Reputation: 82563
Your app's application instance will persist as long as Android allows it to. Whenever the system needs more memory for the foreground or high priority tasks, it will kill your application, including any activity, service and application instances.
There is no set time for which this object will be around. You must write your application assuming that it can be destroyed at any point of time.
You can override onLowMemory() in the Application class to get a rough idea of whether or not you may be killed soon.
Upvotes: 2