當應用程序收到來自GCM的消息時,它會顯示通知。單擊通知後無法重新啓動活動
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_event_white_24dp)
.setContentTitle("TheBriefPost")
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
當我點擊通知時,應用程序會打開活動但不會重新啓動。問題是什麼?如何解決它?
我正在向設備發送GCM消息,以通知「新事件可用」。如果用戶單擊,則應重新啓動活動,以便從頭開始加載數據。這就是爲什麼我需要重新開始活動。無論如何要做到這一點? –