[英]FCM on Android does not trigger `onNewIntent` when app was previously launched from notification
I want to open a proper screen when my app is launched from notification. 从通知启动我的应用程序时,我想打开一个适当的屏幕。 I found a scenario when it doesn't work as I thought it should.
我发现了一个场景,它无法正常运行。
So here is first scenario when it works as it should work: 因此,这里是第一种情况,它可以正常工作:
onNewIntent
of default activity is called. onNewIntent
默认活动的onNewIntent
。 But when app is first launched from FCM notification then step 4. never happens: 但是,当第一次从FCM通知启动应用程序时,则不会执行步骤4:
onNewIntent
of default activity IS NOT CALLED onNewIntent
默认的活动不叫 I found it really problematic to work with and to code against. 我发现使用和编写代码确实很麻烦。 Is this a bug or I am just missing something?
这是一个错误还是我只是缺少一些东西?
EDIT : Default activity launchMode
is set to singleTask
in manifest file. 编辑 :预设活动
launchMode
设置为singleTask
清单文件。
Referring to the previous answer, onNewIntent is called for activities that set launchMode to "singleTop". 参考上一个答案,对于将launchMode设置为“ singleTop”的活动调用onNewIntent。
So first thing you should set up is the manifest file. 因此,您应该设置的第一件事是清单文件。 Set the activity's launchMode to singleTop .
将活动的launchMode设置为singleTop 。 Another thing is to add an intent filter with an action tag.
另一件事是添加带有动作标签的意图过滤器。
sample: 样品:
<activity android:name="youPackage.YourActivity"
android:launchMode="singleTop">
<intent-filter>
<action android:name="youPackage.ACTION">
</intent-filter>
</activity>
And, in your service, you can call new intent provided the action you define in the intent-filter. 而且,在您的服务中,您可以调用新的意图,只要您在意图过滤器中定义了操作即可。
sample: 样品:
Intent i = new Intent("youPackage.ACTION");
Reference: 参考:
Make Sure to override onNewIntent in the launcher activity . 确保在启动器活动中覆盖onNewIntent。 In my case, it was the splash screen.
就我而言,这是启动屏幕。
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intent.getExtras() != null) {
for (String key : intent.getExtras().keySet()) {
Object value = intent.getExtras().get(key);
Log.d("data ", "Key: " + key + " Value: " + value);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.