开发者

Android Defaul Http Client

开发者 https://www.devze.com 2023-03-04 18:04 出处:网络
In my android app i have to get response from the php server. So i used DefaultHttpClient in that i have to maintain session cookies for subsequent requests for that i avoided creation of new instance

In my android app i have to get response from the php server. So i used DefaultHttpClient in that i have to maintain session cookies for subsequent requests for that i avoided creation of new instance for DefaultHttpClient using singleton pattern.But the problem is when i switch off and on the phone app creates new instance for DefaultHttpClient so my session c开发者_Go百科ookies get destroyed.How to maintain DefaultHttClient even when phone restarts?

Thanks.


I suggest you save your cookie data into a persistent storage ( like SharedPreferences / SQLite / or a cookie file ).

Here is a link to more info on Android Storage

You can do this in your onPause() method.

Then you can get the data in your onResume() method.
And of course also check for local cookies in your onCreate()


I recommend using the Android Asynchronous Http Client library, which automatically handles persistent cookie storage to android SharedPreferences.

See the documentation here:

http://loopj.com/android-async-http/#persistent-cookie-storage-with-persistentcookiestore

0

精彩评论

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

关注公众号