As Mark said you can't really do this if you use any of the derived Activity classes (List, Tab, and especially Map). For this kind of "common activity stuff" I created a proxy of sorts - a class that takes an instance of an Activity and implements functions that are common for all. Then each Activity just creates an instance of this proxy with itself and uses it to do the common logic stuff. It's a little more verbose, but works to centralize the common code given the restrictive inheritance hierarchy.
Interesting.But I have a question. If I want to load a new activity and pass some of arguments using this way, I have to get the reference of this new activity, but seems platform doesn't provide any API to get it. How can you do it? I mean how I can get the reference of the new activity. thanks. _____ From: [email protected] [mailto:[email protected]] On Behalf Of TreKing Sent: Monday, December 06, 2010 5:35 AM To: [email protected] Subject: Re: [android-developers] Re: Passing objects to new intents On Sun, Dec 5, 2010 at 2:42 PM, Neilz <[email protected]> wrote: 1) This is useful as you can put a lot of common methods and vars in there,,, As Mark said you can't really do this if you use any of the derived Activity classes (List, Tab, and especially Map). For this kind of "common activity stuff" I created a proxy of sorts - a class that takes an instance of an Activity and implements functions that are common for all. Then each Activity just creates an instance of this proxy with itself and uses it to do the common logic stuff. It's a little more verbose, but works to centralize the common code given the restrictive inheritance hierarchy. 2) I created a load of static objects which, when launching my intents, I populate the static objects so that when the next activity is launched they're there ready. No bundles, no parcelables, simple. What happens when: You start Activity A which initializes a bunch of static objects. >From A you launch Activity B which is depending on these static being initialized by A. You press Home and do other things for an hour or so, eventually your app gets wiped from memory, including the statics. You come back to your Activity, which will start at B since that was the last thing the user saw. A will NOT be called to initialize your statics and B will be using default or non-initialized static data. I would be very careful with using static data to store instance state across Activities. ---------------------------------------------------------------------------- --------------------- TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

