質問

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