如何将附加内容的意图传递给已经运行的活动 [英] How to pass intent with extras to an already running activity
问题描述
我有一个 BroadcastReceiver
,它会启动 HomeActivity
,其中包含一些与附加内容一起传递的信息。
I have a BroadcastReceiver
which launches a HomeActivity
with some information passed with the extras.
当活动已经运行且广播接收器再次被触发并试图启动 HomeActivity
时会发生什么情况新信息。该活动的 OnResume()
或 OnCreate()
是否执行?
What happens when the activity is already running and the broadcast receiver gets triggered again which tries to launch the HomeActivity
with new info. Does the OnResume()
or OnCreate()
of the activity execute?
如果没有,当触发 BroadcastReceiver
时,还有其他方式传递/重新加载正在运行的活动吗? / p>
If not, is there any other way of passing/reloading a running activity when a BroadcastReceiver
is triggered?
推荐答案
确保从BroadcastReceiver启动意图时设置FLAG_ACTIVITY_SINGLE_TOP标志。
Make sure when you are launching the intent from the BroadcastReceiver you set the FLAG_ACTIVITY_SINGLE_TOP flag.
intent.addFlags (FLAG_ACTIVITY_SINGLE_TOP);
...
class HomeActivity extends Activity {
...
@Override
protected void onNewIntent(Intent intent) {
Bundle extras = intent.getExtras();
}
...
}
这篇关于如何将附加内容的意图传递给已经运行的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!