Question

I have added actionbar in every screen of my App. For up navigation I have added following code.

public boolean onOptionsItemSelected(MenuItem item) {
 switch (item.getItemId()) {
    case android.R.id.home:
    NavUtils.navigateUpFromSameTask(this);
    return true;

    .............
 }
 return super.onOptionsItemSelected(item);
}

Now I have four activities, A, B,C and D. In manifest, I also mention C as the parent activity of D, B as the parent activity of C and so on. When I started the A, B, C, D in the same sequence and want to return from D to C, then C to B and so on, I do not want to recreate the Activities again. I want to resume them only just like back button action. But the above code takes the control to parent activity correctly, but recreate them. What is the problem in my code?

Was it helpful?

Solution

Intent parentIntent = NavUtils.getParentActivityIntent(MyActivity.this);
            parentIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
                    | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            NavUtils.navigateUpTo(this, parentIntent);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top