Android 从FireBase云消息中单击通知后恢复活动
我在我的原生安卓应用程序上集成了Android 从FireBase云消息中单击通知后恢复活动,android,firebase,android-studio,firebase-cloud-messaging,Android,Firebase,Android Studio,Firebase Cloud Messaging,我在我的原生安卓应用程序上集成了fire-Base-FCM。目前我有3个活动,splashscreenactivivtiy[Launcher activity],ActivityB,Activityc。当前,当我打开Activityc并单击设备的Home按钮时,应用程序将通过Activityc进入后台。因此,当应用程序在后台运行时,当通知托盘上的FCM发出通知时,在录制通知时,我必须使用前台中的Activityc恢复应用程序。当前,当应用程序处于后台并单击通知时,它将启动我的活动,即我的spla
fire-Base-FCM
。目前我有3个活动,splashscreenactivivtiy[Launcher activity],ActivityB,Activityc
。当前,当我打开Activityc
并单击设备的Home按钮时,应用程序将通过Activityc
进入后台。因此,当应用程序在后台运行时,当通知托盘上的FCM发出通知时,在录制通知时,我必须使用前台中的Activityc
恢复应用程序。当前,当应用程序处于后台并单击通知时,它将启动我的活动,即我的splashScreenActivity[Launcher activity]
。如何避免在后台启动应用程序
private void showNotificationView(String title, String message, RemoteMessage remoteMessage) {
m_notifyId++;
if (m_notifyId == Integer.MAX_VALUE)
m_notifyId = 1;
intent = new Intent(this, Activityc.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, m_notifyId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
String channelId = "com.test.message";
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentIntent(pendingIntent);
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, "com.test.message", NotificationManager.IMPORTANCE_DEFAULT);
manager.createNotificationChannel(channel);
manager.notify(m_notifyId, builder.build());
}
清单文件:
<activity
android:name=".activities.SplashScreen"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".activities.Activityc"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".activities.ActivityB"
android:label="@string/app_name"
android:resizeableActivity="false"
android:screenOrientation="portrait" />
有人能对此提出建议吗??