【发布时间】:2011-08-12 15:48:54
【问题描述】:
我是 android 开发的新手,我需要一些帮助来保存活动的状态。 从 onPause 保存实例并从 onRestore 恢复它的正确方法是什么,因为显然 Android 没有像使用 onCreate 或 onSaveInstanceState 那样发送 savedInstanceState Bundle。或者有没有比使用 savedInstanceState 包更好的保存方法?
这有意义吗?
[编辑] 好的,我想我知道我真正的问题是什么......但首先,我认为我正在寻找的是使用 SharedPreferences 而不是 savedInstanceState。
因此,在查看更多调试日志时,我注意到不是将 Activity 带到堆栈顶部,而是创建一个新的。是的,我意识到我正在创建一个新的......
Intent itemintent = new Intent(MediaList.this, AudioPlayer.class);
Bundle b = new Bundle();
//...putString some strings to send
itemintent.putExtra("android.intent.extra.INTENT", b);
itemintent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivityForResult(itemintent,0);
...但是 FLAG_ACTIVITY_REORDER_TO_FRONT 不应该阻止它创建新活动吗?我猜它认为它必须创建一个新的,因为我正在发送一些字符串?
更好的是,只要字符串相同,我如何检查活动是否已经在堆栈中并切换到它? - 当用户从列表视图中单击媒体项目时,我开始此活动。 [/编辑]
【问题讨论】: