我有问题,关于如何关闭应用程序,当用户点击通知从托盘和打开活动。 整个场景如下: 例如我的应用程序名称是testdemo
。如何关闭当前打开的应用程序,当点击推送通知
假设testdemo
应用程序当前打开,用户在应用程序中做一些工作。当时推送通知到达与testdemo
应用程序有关。
在这种情况下,用户已经打开testdemo
应用程序,但当点击通知时,它再次打开testdemo
应用程序。但是我想关闭当前的应用程序而不是打开的应用程序。由于当新应用程序关闭的时候也是testdemo
应用程序,但是最后一个屏幕已经被用户点击通知之前打开。
我发送通知如下:
private void sendNotification(String title,
String message,
String receiverUid) {
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("uid", receiverUid);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent pendingIntent = PendingIntent.getActivity(this, ++NOTIFICATION_ID, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_alert)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(++NOTIFICATION_ID, notificationBuilder.build());
}
Thnks的答案。你能给出例子或引用的链接,以获得确切的想法。 – ashish
@ashish,好的。 DONE – Vyacheslav