Thanks Farproc, that all makes sense. The documentation here: http://developer.android.com/intl/de/resources/faq/framework.html#3
talks about "A public static field/method" way of passing data to activities. 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? 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? If so, then Activity1 can't be used to set up the static used by Activity2. Would be really useful if someone could confirm this. On Mar 8, 7:29 am, Farproc <[email protected]> wrote: > > I thought if I set a static field then that will stay set as long as > > the VM is alive. > > I agree with you. > > But you can't make such an assumption that "MyActivity.onCreate()" > will be always executed in the same VM process as > "MyActivity.COMPLEX_OBJ = myComplexObj; // which is definitely NOT ". > The first time you launch MyActivity, they are in the same VM > instance, but after that MyActivity may be paused(as the user press > home key) and then the VM process may be killed if extra > resources(memory etc) are need by other applications. > What will happen if the user long press home and come back to > MyActivity again? A new VM process will be created, a new instance of > MyActivity will be created and resumed! "MyActivity.onCreate()" will > be executed in a completely new VM process this time!! > > NOT TESTED AND VERIFIED! > > On Mar 7, 6:12 pm, westmeadboy <[email protected]> wrote: > > > > > When starting a new Activity, I want to pass a complex object and do > > so by using this approach: > > > MyActivity.COMPLEX_OBJ = myComplexObj; // which is definitely NOT > > NULL! > > Intent intent = new Intent(); > > intent.setClass(this, MyActivity.class); > > startActivity(intent); > > > and then in MyActivity: > > > @Override > > public void onCreate(Bundle bundle) { > > if (COMPLEX_OBJ == null) { > > // report to Flurry > > ... > > } > > ... > > > } > > > When I've tested this on my devices, everything works fine. > > > However, from Flurry analytics, I see that COMPLEX_OBJ is sometimes > > null! But I've checked my code 100 times and can say it is absolutely > > not possible that COMPLEX_OBJ is being set with a non null value. > > > My initial guess was that onCreate() was being called before > > startActivity() - is this possible? BTW, the activity is defined in > > the Manifest without any intent filters. > > > Then I found this: > > >http://developer.android.com/intl/de/guide/appendix/faq/framework.html#3 > > > which says: > > > "But, the life cycle of a static is not well under your control" > > > I thought if I set a static field then that will stay set as long as > > the VM is alive. Or have a misunderstood something? -- 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

