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?

有帮助吗?

解决方案

Intent parentIntent = NavUtils.getParentActivityIntent(MyActivity.this);
            parentIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
                    | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            NavUtils.navigateUpTo(this, parentIntent);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top