Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 打开应用程序';通知后的主要活动单击+;背压_Android_Android Studio_Android Intent_Push Notification_Taskstackbuilder - Fatal编程技术网

Android 打开应用程序';通知后的主要活动单击+;背压

Android 打开应用程序';通知后的主要活动单击+;背压,android,android-studio,android-intent,push-notification,taskstackbuilder,Android,Android Studio,Android Intent,Push Notification,Taskstackbuilder,如果用户单击通知,然后单击后退按钮,我想从头开始打开我的应用程序(即打开主活动)。我看了所有的答案,应用了它们,但我没有达到我想要的。 我的应用程序启动时带有Splashscreen活动,如果您正常启动,则主活动将运行。单击通知时,我正在打开一个不同的活动(在webview中显示),顶部有一个后退按钮,主要活动是不参与这种情况。有两种情况。如果应用程序在后台,我的以下代码正在工作(按下时返回到主活动),但如果应用程序不在后台(从未打开),则应用程序在按下后立即关闭。在这种情况下,我想通过启动主活

如果用户单击通知,然后单击后退按钮,我想从头开始打开我的应用程序(即打开主活动)。我看了所有的答案,应用了它们,但我没有达到我想要的。 我的应用程序启动时带有Splashscreen活动,如果您正常启动,则主活动将运行。单击通知时,我正在打开一个不同的活动(在webview中显示),顶部有一个后退按钮,主要活动是不参与这种情况。有两种情况。如果应用程序在后台,我的以下代码正在工作(按下时返回到主活动),但如果应用程序不在后台(从未打开),则应用程序在按下后立即关闭。在这种情况下,我想通过启动主活动从头开始打开我的应用程序

这些是相关活动的清单代码:

    <activity
        android:name="xxx.activities.SplashScreenActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="xxx.activities.MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity
        android:name="xxx.activities.ShowInWebviewActivity">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    public class Notifications extends FirebaseMessagingService {

        @Override
        public void onMessageReceived(RemoteMessage remoteMessage) {
            
            // This is the intent for notification click
            Intent notificationIntent = new Intent(this, ShowInWebviewActivity.class);
            
            // I've generated the trace in here
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
            stackBuilder.addNextIntent(new Intent(this, MainActivity.class));
            stackBuilder.addNextIntent(notificationIntent);

            // Created pending intent 
            PendingIntent pendingIntent = stackBuilder
                .getPendingIntent(new Random().nextInt(), PendingIntent.FLAG_ONE_SHOT);

    }