Cookie management and saving state in Android apps.

I just wrote my first Android app using the ADT plugin for Eclipse. This particular app I wrote interacts with existing web services we deployed on our main production servers. I was having the hardest time maintaining a session state during web service calls on the back-end. All I needed was the following one line of code in my onCreate function of the Activity which calls the web service that sets up the session:

CookieHandler.setDefault(new CookieManager( null, CookiePolicy.ACCEPT_ALL));

Presto! State saved across all subsequent web service calls.

Leave a comment