根据我从Gmail和TED应用程序观察到的向上导航的行为,它将导航到具有相同状态(滚动位置)的父级,而不像谷歌在他们的文档中所说的实施向上导航,就像创建父意图并启动它一样.
我实现了Android示例代码中的代码,所有状态都消失了(我之前设置的所有额外参数和滚动位置).这是什么方法?我在Android文档上找不到任何内容.
以下是代码:
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent upIntent = new Intent(this, MyParentActivity.class);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
// This activity is not part of the application's task, so create a new task
// with a synthesized back stack.
TaskStackBuilder.from(this)
.addNextIntent(new Intent(this, MyGreatGrandParentActivity.class))
.addNextIntent(new Intent(this, MyGrandParentActivity.class))
.addNextIntent(upIntent)
.startActivities();
finish();
} else {
// This activity is part of the application's task, so simply
// navigate up to the hierarchical parent activity.
NavUtils.navigateUpTo(this, upIntent); …
Run Code Online (Sandbox Code Playgroud)