13

In the Android Activity lifecycle, when Activity.onCreate() is called after resuming (IE. not when activity created initially or in response to screen rotation) would this code return a valid (non-null) Bundle?

public void onCreate(Bundle savedInstanceState) {
    Bundle b = this.getIntent().getExtras();
    // is b == null? (when activity is resumed)
}

I am trying to reproduce a problem that occurs when the application has not been used for a long period - when the user returns, the application crashes.

0

2 Answers 2

14

okay, so when Android kills my app and the user navigates back - onCreate() is fired with a >new< Activity, and the original Intent along with it's associated Extras is gone; or do the Extras get attached to the new Intent by Android?

I was wondering the same thing and tested this quickly in my application.

It turns out intent extras are available when an activity is re-created after your application got killed.

1
  • Thank you for answering this -- it is a more concise explanation of what people seem to be wanting to know when they come here. I would delete mine if I could so people would stop commenting on it and instead see yours. Jul 3, 2013 at 9:51
2

I would put that code in onResume() so it will be available when returning to the foreground.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.