Удаление активности запуска из стека на pendingIntent

1

У меня есть проблема. Когда мое приложение не в фоновом режиме (удалено из последних) все работает нормально. Но когда мое приложение работает недавно, а затем я открываю "ResponseActivity" с помощью уведомления в ожидании намерения, при обратном щелчке на "ResponseActivity" я попадаю в MainActivity (действие Launcher). Я добавил FLAG_ACTIVITY_NEW_TASK, но, похоже, он этого не делает.

    Intent intent = new Intent(this, ResponseActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP   | Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_launcher_background)
            .addAction(0, "Other", pendingIntent) 
            .setLargeIcon(getCircleBitmap(bitmap))
            .setContentTitle(userDB.getName())
            .setContentText(smallText)
            .setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL)
            .setColor(getResources().getColor(R.color.colorPrimary))
            .setPriority(NotificationCompat.PRIORITY_DEFAULT);


    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = mNotificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID);

        channel.setDescription("");
        channel.enableLights(true);
        channel.setLightColor(Color.RED);
        channel.enableVibration(true);

        mNotificationManager.createNotificationChannel(channel);
    }

    mNotificationManager.notify(1000, mBuilder.build());

Manifest:

<application
    android:name=".ApplicationContextProvider"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".SplashActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service
        android:name=".MyFirebaseInstanceService"
        android:stopWithTask="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <activity android:name=".MainActivity" />
    <activity android:name=".LoginActivity" />

    <activity android:name="verification.MyVerifyPhoneActivity" />
    <activity android:name=".ResponseActivity"
        android:theme="@style/AppTheme2">

    </activity>
</application>
Теги:
android-pendingintent

1 ответ

1
Лучший ответ

Если вы хотите быть уверены, что при выборе Уведомления в стеке находится только стек ResponseActivity, вы можете сделать это:

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);

вместо:

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

Ещё вопросы

Сообщество Overcoder
Наверх
Меню