나는이 방법이 여기에 게시 사용하여 액션 바에서 위로 버튼을 구현하고있다 :구현 액션 바 상 버튼
ActionBar Up button and Navigation pattern
그것은 하나 개의 시나리오를 제외하고 작품을 좋아 : 활동 A가 다음 활동 B를 생성하고, 경우에 나는 눌러 위로 이동하면 아무 문제 없습니다.
그러나 Activity B에 도착한 다음 다른 App으로 전환 한 다음 다시 내 App으로 전환하면 Up 버튼을 누르면 Activity A 대신 홈 화면으로 이동합니다.
디버깅 할 때 NavUtils.shouldUpRecreateTask (this, upIntent)가 두 경우 모두 false를 반환하고 upIntent가 두 경우 모두 실제로 Activity A임을 알 수 있습니다. 문제가 무엇인지 잘 모릅니다.
@SuppressLint("NewApi")
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
if (itemId == android.R.id.home) {
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
// This activity is NOT part of this app's task, so create a new task
// when navigating up, with a synthesized back stack.
TaskStackBuilder.create(this)
// Add all of this activity's parents to the back stack
.addNextIntentWithParentStack(upIntent)
// Navigate up to the closest parent
.startActivities();
} else {
// This activity is part of this app's task, so simply
// navigate up to the logical parent activity.
NavUtils.navigateUpTo(this, upIntent);
}
//finish();
return true;
} else if (itemId == R.id.wrap_menu_item) {
wrapText();
invalidateOptionsMenu();
return true;
} else {
return super.onOptionsItemSelected(item);
}
}
내 용서를 용서했으나 안드로이드가 활동 기록을 기반으로 자동으로 위 작업을 처리했다고 생각 했습니까? – cgTag
http://developer.android.com/training/implementing-navigation/ancestral.html – user1159819
안드로이드에서 코드를 작성하면 모든 것을 잘 유지할 수 있습니다. 당신의 질문에'onOptionsItemSelected'에서 코드를 공유 할 수 있습니까? 도움이 될 것입니다. – cgTag