Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Android restore Intent extras when resuming Activity?

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.

like image 259
StrayPointer Avatar asked Dec 19 '11 17:12

StrayPointer


1 Answers

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.

like image 114
Alexis Avatar answered Sep 19 '22 12:09

Alexis