Maintaining Intent Extra over configuration changes

98
May 11, 2018, at 11:52 AM

I have a Game activity which is launched from MenuActivity with startActivity(intent). The intent is obtained with the following method, in which a "model" object is passed. Note that the given argument is never null and Model implements Parcelable.

public static Intent createIntent(Context context, Model model) {
    final Intent gameIntent = new Intent(context, GameActivity.class);
    gameIntent.putExtra(KEY, model);
    return gameIntent;
}

inside GameActivity I get the intent data like that:

@Override
protected void onCreate(Bundle savedInstanceState) {
    [...super.onCreate(savedInsatnceState), view initialization and so on...]
    // get intent data here
    if (savedInstanceState != null) {
        mModel = savedInstanceState.getParcelable(KEY);
    } else {
        mModel = getIntent().getParcelableExtra(KEY);
    }
}

Then I care about maintaining the received intent extra...

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    mModel = savedInstanceState.getParcelable(KEY);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putParcelable(KEY, mModel);
}

I thought it was impossible to lose the given argument (model). However, it happened on a remote device that mModel was null after onCreate() and I have no clue about how that could be possible. So the question is: Am I missing one or more cases in which mModel could not be initialized after onCreate(), given the above code?

Thanks

READ ALSO
Using Android Camera2, when is the appropriate time to show the TakePicture button

Using Android Camera2, when is the appropriate time to show the TakePicture button

I'm using the Android Camera2 APII would like to know when is the appropriate time to:

114
Location Listener in doInBackground() of Async Task

Location Listener in doInBackground() of Async Task

Is it possible to get continuous location updates in the doInBackground() method of an Async Task?

94
getting user id from rails token in android

getting user id from rails token in android

I'm trying to update a user through android app to our server, but the server keeps throwing me a 404 error

110
How to design Android UI/UX for this specific need? [on hold]

How to design Android UI/UX for this specific need? [on hold]

I have a list of some kind of so called rulesAnd I want the user to create an Item in "addItemActivity" in which the user will add as much as rule wanted

73