views:

272

answers:

3

Hi all,

I am trying to maintain my session variables that I get back in a cookie from my website in my DefaultHttpClient by passing the client between activities. Simply put how can I pass this object between activities to maintain my session variables? Bundle.put... doesn't seem to support this object. If it does how does it work with DefaultHttpClient?

Thanks in advance to anyone who can help.

+1  A: 

From the Android FAQ: How do I pass data between Activities/Services within a single application

I use the one where you subclass android.app.Application.

synic
Let me see if I understand this correctly:1. add a service to the manifest.2. make the class in the main activity that contains the instansiation of my DefaultHttpClient objectThen when the application loads it loads the subclass first and then all my activities in seperate files will be able to see the subclass and they they will also see the DefaultHttpClient object. Further, when using the DefaultHttpClient in the other activities the object will be the same instance everywhere it is used maintaining my session variables....Please let me know if I've got it.
searchMaker
Not a service, a subclass of android.app.Application. Then all activities will be able to see that subclass by calling getApplication()
synic
thanks for your help I think I can take it from here.
searchMaker
I am having trouble accessing the vairable I made in my subclass from my activity. The string variable I made in my globalHttp subclass is TRYG and my TextView just dispays and empty string when TRYG is set to "Hello".globalHttp my = (globalHttp)getApplicationContext();results2.setText(":::::" + my.TRYG + "::::::");
searchMaker
I figured out what I was doing wrong, whoot whoot.
searchMaker
+1  A: 

You can make objects public static

Vishal
+1  A: 

You can use the Singleton Pattern (introduced by Gang-of-Four)

Advantage of Singleton:

This is useful when exactly one object is needed to coordinate actions across the system.

The Elite Gentleman