> 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

Reply via email to