我的应用程序中有活动A,B和C,它们按顺序流动.如果我在C中实现Up按钮,我希望它返回到B. Eclipse生成的代码存根是:
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case 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.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
Run Code Online (Sandbox Code Playgroud)
但是,B期望在其onCreate方法中从A传递额外内容.B和C之间的关系是C允许用户设置一些影响B显示方式的设置.我目前正在处理在onPause()中保存C中的更改.当用户按下Up而不是调用navigateUpFromSameTask(this)时,我应该完成()C吗?
如果您要从C返回B ,如果您使用标准启动模式,您的活动将再次创建.onSaveInstanceState 不会(可靠地)工作.
将活动B的启动模式声明为:
android:launchMode="singleTop"
Run Code Online (Sandbox Code Playgroud)
在AndroidManifest.xml中,如果要返回到您的活动.请参阅文档和解释.
| 归档时间: |
|
| 查看次数: |
1418 次 |
| 最近记录: |