通知后,我想退出并返回主屏幕?

After notification, I would like to exit and go back to main screen?

我第一次测试 android 通知。我在一个有联系人列表的页面上,我点击一个来触发我的通知。通知让我进入了带有这些按钮的页面

我点击贪睡,然后我点击 10 分钟按钮,此时,我打电话给

    finish();
    System.exit(0);

我在这个 post

中找到的

但是,该应用程序并没有退出,而是再次返回到暂停和快速文本选项,这非常令人困惑。

我如何退出应用程序或者如果用户正在使用该应用程序,返回到通知进入之前打开的页面? (即,用户最好返回包含我认为的联系人列表的页面)

我不确定它是否相关,因为我不知道哪些信息很重要,但这是我在用户点击联系人时触发的通知代码

private void displayNotifiation(Contact contact, byte[] img) {
    int notificationId = contact.hashCode();

    Bitmap bitmap = BitmapFactory.decodeByteArray(img, 0, img.length);

    // Create an explicit intent for an Activity in your app
    Intent intent = new Intent(mContext, ActivityNotificationLanding.class);
    Uri uri = Uri.parse("http://notexist.mykeepintouch.app/contactid/"+contact.getId());
    intent.setData(uri);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    gson.putExtra(intent, IntentFlashStore.CONTACT_KEY, contact);
    intent.putExtra(NOTIFICATION_ID, notificationId);
    PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    Log.d(TAG, "onClick: put info="+contact.getName()+" notifId:"+notificationId);


    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext, MainActivity.CHANNEL_ID)
            .setSmallIcon(R.drawable.plus_icon5)
            .setContentTitle("It's time to reach out to "+contact.getName())
            .setContentText("For your health")
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setLargeIcon(bitmap)
            .setContentIntent(pendingIntent)
            .setAutoCancel(false);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mContext);

    // notificationId is a unique int for each notification that you must define
    notificationManager.notify(notificationId, builder.build());
}

你可以改变

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

intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

当你点击按钮时只调用 finish()