开发者

Android: Determine when app is being finalized

开发者 https://www.devze.com 2022-12-24 16:13 出处:网络
I posted a question yesterday about determining when an app is being finalized vs destroyed for screen orientation change. Thanks to the ans开发者_如何学Gowers I received I was able to resolve my prob

I posted a question yesterday about determining when an app is being finalized vs destroyed for screen orientation change. Thanks to the ans开发者_如何学Gowers I received I was able to resolve my problem with the screen orientation change. However, I am still running into a roadblock. This app I am working on logs into a website with an HttpClient. As long as the app remains in memory the HttpClient will retain the cookies from logging in. However, once it is killed, it would need to log in again. My question: How can I determine when the app is being killed from memory so I can set a boolean to false telling the app it has been removed from memory so the next time it starts it will read this and determine is must log in again? Or is it possible to serialize an HttpClient and put that in the savedInstanceState bundle? May extract the cookies from the client and put those in the savedInstanceState bundle? Is there something I'm completely missing here maybe? Any help or a point in the right direction is greatly appreciated because this one has me stumped. Thank you!


How can I determine when the app is being killed from memory so I can set a boolean to false telling the app it has been removed from memory so the next time it starts it will read this and determine is must log in again?

IMHO, that's the wrong question.

The right question is: "how can I tell that the cookie is gone?"

This is much closer to the real business problem ("how do I know if I have to log in again?") and therefore will cover more potential edge and corner cases than assuming that some system event is the only source of the cookie vanishing.

Besides, it's easier: your HttpClient object can give you access to the CookieStore, and you can iterate over those cookies to see if yours is in there. Admittedly, it'd be nice if they had a more direct method on that class for such a lookup.

So, before you do an access to the Web app, check to see if the cookie is there, and pop up the login dialog/activity/whatever if needed.

Or is it possible to serialize an HttpClient and put that in the savedInstanceState bundle?

No.

May extract the cookies from the client and put those in the savedInstanceState bundle?

Yes, but then you'll have a devil of a time putting them back in the CookieStore, IIRC.

0

精彩评论

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

关注公众号