【发布时间】:2014-08-05 06:04:25
【问题描述】:
Activity A 启动 Activity B。在 Activity B 中,我有这个方法:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpTo(this, new Intent(this,
ArticleListActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
当我按下主页按钮时,它会将我带到应有的活动 A。但是,再次调用 onCreate。我不希望这种行为。
我猜是因为这个实现对导航堆栈中的前一个项目使用了新的 Intent。这只是我在创建双窗格项目时从 Eclipse 获得的代码。我环顾四周,发现堆栈溢出,虽然似乎使用 Intent 返回会导致这种行为,但我不明白为什么 Google 会在默认模板中提供这个。
我应该如何以不同的方式进行此调用,以便在返回 Activity A 时不会再次调用 onCreate?
【问题讨论】:
-
你可以调用 onBackPressed()
-
只要完成这个活动,即调用 this.finish();
标签: android android-intent android-activity