【发布时间】:2010-11-15 10:32:20
【问题描述】:
我有一个通知,它启动我的活动并使用意图的 putExtra() 函数传递消息。然后该消息在活动的 onCreate 函数中显示给用户。当应用程序由于方向改变而重新启动时,消息会再次显示,因为它仍然在 Intent 的捆绑数据中。
如何删除多余的数据?
我尝试了以下方法:
Bundle bundle = getIntent().getExtras();
if (bundle.getBoolean("showMessage")) {
// ... show message that is in bundle.getString("message")
// remove message
bundle.remove("showMessage");
}
但是仍然显示在方向改变后仍然显示,似乎使用的意图不是我改变的意图,而是原来的。我发现的唯一解决方法是将 showMessage 额外保存在 onSaveInstanceState() 中。
还有其他方法吗?或者这是要走的路?
【问题讨论】:
标签: android android-intent bundle