Global Objects possible?

Put your problem here if it does not fit any of the other categories.

Global Objects possible?

Postby paradroid666 » Tue Jun 01, 2010 8:16 am

Hi,

I have an application which consists of two activities. I want now to have some data objects which are global to my application, so that I can access them from both activities. Usually I create my objects in the onCreate method but then they are local. Can I have something like these global data objects?

Can I somewhere enter some global code that will be executed where I decide which activity is called?

Thanks.
P.
paradroid666
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri May 21, 2010 2:36 pm

Top

Re: Global Objects possible?

Postby anarche » Tue Jun 01, 2010 12:17 pm

You can serialise them and write them to file, to share between the apps.

Perform the serialisation in onStop() and deserialisation in onStart().

I can't think of any other way of sharing objects between Activities. If you need this for the design of your app, can I suggest you redesign the app? Maybe replace the second Activity with a Dialog?
anarche
Master Developer
Master Developer
 
Posts: 369
Joined: Sun Apr 11, 2010 5:21 am

Re: Global Objects possible?

Postby pskink » Tue Jun 01, 2010 12:37 pm

see:

http://developer.android.com/intl/fr/gu ... ement.html

and create your Application class

then you can call getApplication() to get its singleton instance
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 12 guests