I have a PersistentCookieStore and I want to use it globally so it means It writes cookies into it in login.java, and I want to perform requests with theese cookies in mainactivity.java How can I do this? Actually I declare the PCS like this:

PersistentCookieStore myCookieStore = new PersistentCookieStore(this);
client.setCookieStore(myCookieStore);

But I cant do this in both classes because then it would be new every time, or am I wrong? :o

Regards,

有帮助吗?

解决方案

Assuming you're using the android-async-httplibrary then PersistentCookieStore is persistent so it stores any Cookies you add to it in Shared Preferences. This means if you create instances of it in different Activities they will all have access to the same cookies.

In other words, if you write cookies to an instance of PersistentCookieStore in Login.java they will be available to a different instance of PersistentCookieStore in MainActivity.java.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top