The general situation is that I want multiple activities to have access to a single database (which needs to be open all the time since its the basis of just about every function/feature).
Two approaches I can think of: 1. Quick and dirty workaround: In the example I gave, if Activity2.onCreate() is called and the static has not been set, then call finish(). I assume this will this just lead to Activity1 being created? If so, that would be OK, for me. 2. Long-term good-practice approach: Handle opening/closing database in the Application object. This seems like a logical place to put this code. Initially, my app was just one activity and so I did all the app configuration in that activity's onCreate() method. It felt wrong then, and now I know why :) Any thoughts? On Mar 8, 1:25 pm, Mark Murphy <[email protected]> wrote: > westmeadboy wrote: > > But it seems that its important to know that you can't just set that > > at the point you call the new activity. Instead it seems you have to > > set it every time the VM is (re)created? > > Yes. This is one of the many reasons to avoid such statics, particularly > for dynamic or mutable data. > > > If you start Activity2 from Activity1 and the user hits home in > > Activity2 and the VM gets killed...then when the user returns to the > > app, Activity2 will get recreated, but Activity1 won't, right? > > Not immediately, no. > > > If so, > > then Activity1 can't be used to set up the static used by Activity2. > > Correct. > > > Would be really useful if someone could confirm this. > > Hi! Farproc speaks truth! :-) > > >>> When starting a new Activity, I want to pass a complex object > > Ick. > > If this is truly transient state, make the object be Parcelable. > > Otherwise, I encourage you to rethink your plan. Perhaps you need to > make those be one single activity rather than two. Or perhaps you need > the data to be mediated by another component (e.g., a service). Or, > perhaps you need the data to be static, but via some singleton object, > where that object is capable of lazy-rebuilding the data when needed > after a VM restart. > > -- > Mark Murphy (a Commons > Guy)http://commonsware.com|http://twitter.com/commonsguy > > Android Online Training: 26-30 April 2010:http://onlc.com -- 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

