Even though the android process is killed,the activity stack is maintained.
For Example:
I have crossed four screens in my app and cookies are stored in CookieManager
. Now i am pressing the home button and the android kills the process.Since the process is killed android CookieManager instance is also killed(all cookies stored are removed).
When I am resuming to the app,it starts from the activity i left but cookies are no more now.
Possible solutions: (Considering Html(WebView) + android is used in app)
Need to maintain the cookies in persistence storage.(Not relying on Android CookieManager).
Challenges:
webview uses cookieManager to store its cookie. we need to sync our cookies with the webView cookies(cookies stored in cookie Manager).
when to remove all persisted cookies.do we have any android specific call back for application exit?
Restart the application from starting(from where the cookie is established) if the process is killed.
Possibile Soln:
Android Application class's oncreate will be called when the new process is created.That point of time, we can start the application from starting.Is there any better solution for this?
If we are implementing a custom class for maintaining the cookie, what is point in having android CookieManager?
I am going to assume that this "Cookie Manager" is a static data member.
The "Cookie Manager" will be gone, along with all the other objects in memory, when the process is terminated.
Save the cookies in a persistent store, such as a file, database, or
SharedPreferences
. Or, if the cookies are small in aggregate size, and it makes logical sense for your app, have them be part of theBundle
that is handed to you viaonSaveInstanceState()
of your activities and fragments.