我有一个带有 MediaPlayer 的现有 Activity ,它在调用 onStop() 后仍在运行。
我想重新加载这个 Activity ,但要传递不同的额外值。
Intent intent = new Intent(WelcomeScreen.this, PlayMusic.class);
intent.putExtra("plan", 0);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
但是,无论我在新 Intent 上放置什么,这个额外的值都会“卡住”相同的值。
有什么想法吗?
最佳答案
正如您明确指出的那样,您创建了一个新的 Intent 对象。无论与旧 Intent 关联的参数是什么,即最初用于创建 Activity 的参数,它们都不会受到影响。
但是,您可以通过覆盖 Activity 的 onNewIntent() 来访问新的 Intent。方法:
@Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
if ( intent != null && intent.hasExtra("plan") )
{
// Yay! Do whatever... Live long... Prosper...
}
}
关于android - Intent extras 没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20049225/