TMH
TMH

Reputation: 6246

onSaveInstanceState not running

I've got a simple orderride on my onSaveInstanceState()

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    Log.d("FUApp", "savingInstanceState");
    if (haveLocation) {
        outState.putParcelable("theLocation", theLocation);
        Log.d("FUApp", "Location stored");
    }
    else
    {
        Log.d("FUApp", "Location wasn't stored");
    }
}

and then I have this method for startingActivities

public void setupStartActivityIntent(Context base, Class clss, Bundle mBundle) {
    Intent intent = new Intent(base, clss);
    if (mBundle != null) {
        intent.putExtras(mBundle);
    }
    if (currentAPIVersion >= 16) {
        Bundle translateBundle = ActivityOptions.makeCustomAnimation(
                base,
                R.anim.slide_in_left,
                R.anim.slide_out_left
        ).toBundle();
        startActivity(intent, translateBundle);
    } else {
        startActivity(intent);
    }

Should onSaveInstanceState get ran before the new Activity starts? I'm trying to minimize the number of location request my app is doing.

Upvotes: 0

Views: 162

Answers (1)

Robby Pond
Robby Pond

Reputation: 73494

That is only called when the application is killed. In this case if you kill the new activity or go back to the previous the Activity will just be resumed and not restarted. The method signiature for onSaveInstanceState explains when it is called.

Upvotes: 1

Related Questions