Android 单端活动未检测到意图
我有一个定义为singleTop的活动,因此只有一个实例存在Android 单端活动未检测到意图,android,android-intent,notifications,Android,Android Intent,Notifications,我有一个定义为singleTop的活动,因此只有一个实例存在 <activity android:name=".MyMainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:launchMode="singleTop" and
<activity
android:name=".MyMainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:launchMode="singleTop" android:multiprocess="true">
如果activity未运行,则intent会按预期通过onCreate()启动活动
如果活动正在运行,但处于停止状态/不在前台(如单击“主页”按钮),并单击了通知,则会按预期调用我的活动的onNewIntent()
但是,如果活动在前台时已被调用,则不会调用onNewIntent()
我如何设置此通知,以便在处于暂停/停止状态时(在我提到的其他情况下也仍然有效),向我的singleTop活动发送意图。我想在我的notificationIntent对象上设置一个标志,但是对于单端活动来说,这些标志的功能并不明确。如果您的应用程序由多个活动组成,那么如果您希望接收一个
onNewIntent(),则需要将剩余的活动定义为singleTop
当该活动处于活动状态时调用
假设主要活动是A
,定义为singleTop
,然后从那里开始活动B
,而不是定义为singleTop
。如果现在选择调用应用程序的通知,应用程序将在活动B
上启动,但未调用onNewIntent()
您还可以通过添加标志
Intent来覆盖此行为。标志
从堆栈中删除活动B
,活动A
将接收对onNewIntent()
的调用。在这种情况下,是否调用了其他方法?不,不基于我的日志记录。onCreate()、destroy、resume、pause、onSaveInst、onrestoreinnst这似乎只是某些设备上的问题。我正在处理一个类似的场景,我有一个设备工作正常,另一个没有收到新的意图。在my intent上设置CLEAR\u TOP
标志,将其固定在出现问题的设备上。在我的情况下,我的主要活动A是我希望通过通知显示的内容。因此,在通知没有对我的活动A调用onNewIntent()的情况下,活动B不在堆栈上。在我的情况下,添加Intent.FLAG\u activity\u CLEAR\u TOP是有效的。调用了onNewIntent()。
Intent notificationIntent = new Intent(context, MyMainActivity.class);
notificationIntent.setAction(MyMainActivity.CustomInternalMessageAction);
notificationIntent.putExtra(MyMainActivity.ReceiveTestMessage, rawMessageText);
...
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
mNotificationManager.notify(number, notification);