當我的通知關閉時,我想恢復放入後臺的活動,而不是開始新活動。我已經看到一些關於使用FLAGS的答案,但我不知道如何實現它如何通過單擊通知恢復以前的活動
contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | INTENT.FLAG_ACTIVITY_SINGLE_TOP);
我在哪裏可以把這個放在我的代碼中?我試過了,但沒有奏效。請幫忙!
ns = Context.NOTIFICATION_SERVICE;
mNotificationManager = (NotificationManager) getSystemService(ns);
icon = R.drawable.icon;
tickerText = "Short Msg";
when = System.currentTimeMillis();
notification = new Notification(icon, tickerText, when);
context = getApplicationContext();
contentTitle = "MyApp";
contentText = "Reopen App";
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationIntent = new Intent(this, StartTimer.class);
contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);