gpt4 book ai didi

android - 从 pendingIntent 的堆栈中删除启动器 Activity

转载 作者:行者123 更新时间:2023-11-29 23:26:51 25 4
gpt4 key购买 nike

我有一些问题。当我的应用程序不在后台(从最近删除)时,一切正常。但是当我的应用程序是最近的,然后我通过通知挂起 Intent 打开“ResponseActivity”时,在“ResponseActivity”上单击后退我进入我的 MainActivity(启动器 Activity )。我已经添加了 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());

list :

<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>

最佳答案

如果您想确保在选择通知时只有 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);

关于android - 从 pendingIntent 的堆栈中删除启动器 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53414780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com