在startActivity(new Intent)之后在onResume()中获取旧的intent intent

时间:2012-03-29 13:06:24

标签: android

在调用活动中,我有以下代码:

Intent intent = new Intent();
intent.setClass(CallingActivity.this, CalledActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(key, new_value);
startActivity(intent);

在调用startActivity(intent)之后,控件转到CalledActivity的onResume()。

但是,在CalledActivity的onResume()中,getIntent()给出了旧的意图,而不是CallingActivity设置的新意图。

如何在CalledActivity的onResume()中获取新意图?

2 个答案:

答案 0 :(得分:13)

您应该尝试覆盖Activity的onNewIntent (Intent intent)方法,并使用setIntent(Intent)来更新意图。

答案 1 :(得分:4)

要扩展梦之谜的答案,只需将以下方法添加到您的活动中。

@Override
public void onNewIntent (Intent intent) {
    setIntent(intent);
}