Android Process Killed - is CookieManager instance killed?

1.3k views Asked by At
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)
  1. 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?

  2. 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?

1

There are 1 answers

2
CommonsWare On

I have crossed four screen in my app and cookie are stored in Cookie Manager.

I am going to assume that this "Cookie Manager" is a static data member.

Now i am pressing the home button.now the process is killed. Then the Cookies stored will also be removed.

The "Cookie Manager" will be gone, along with all the other objects in memory, when the process is terminated.

If that is the case, how can we maintain the consistency in app. The Cookies which ever stored is removed since process is killed but the app is resuming from the activity we left.

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 the Bundle that is handed to you via onSaveInstanceState() of your activities and fragments.