2

I'm sorry in advance if this question is not good enough to be asked, But i made a lot of search to get the proper approach to store cookies in my android app which makes a lot of web connections.

I found more approaches deals with storing cookies in android app, But i can't determine what is the proper one, Or when i should use one rather than others !!

I'll write some of what i found not all:-

  • SharedPreferences approach.
  • CookieManager approach.
  • HttpCookie approach.

The most two things i consider about cookies storing are security and long-lived age of cookie.

Noah
  • 141
  • 3

1 Answers1

2

It depends on how you want to use them:

  1. Only SharedPrferences approcach allows persistent cookie storage. For example if you do not want user perform login every time he runs your app.
  2. CookieManager is used internaly by WebView. It keeps cookies in

    class InMemoryCookieStore implements CookieStore
    

so it is not persistent.

  1. HttpCookie is used by HttpClient. It is just cookie representation and it doesn't responsible for their storage.
Kirill Popov
  • 310
  • 1
  • 2
  • 11
  • 1
    How much secure the SharedPrferences approach ? – Nedal Eldeen Aug 22 '15 at 10:07
  • 1
    @NedalEldeen Look at Context.getSharedPreferences() If you will use 0 or MODE_PRIVATE it will be accessible only for your application. Of course it couldn't help if malicious app has root access. – Kirill Popov Aug 22 '15 at 12:56