0
我有我的應用程序設置通知的地方,當它被點擊時,我想知道在程序中。每次點擊時,主要活動都會打開,但偶爾偶爾會遇到一個錯誤,在單擊通知時未調用onNewIntent(Intent intent)。這裏是我的onNewIntent:有時onNewIntent()不被觸發
@Override
public void onNewIntent(Intent intent) //when notification is clicked
{
Log.i("mydebug","Notification clicked.");
}
,這裏是該通知創建:
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setWhen(System.currentTimeMillis())
.setContentTitle(schedname)
.setContentText("Click to deactivate this silence schedule.")
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_launcher);
//notification.flags |= Notification.FLAG_NO_CLEAR; //Notification cannot be clearned by user
NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
// Uses the default lighting scheme
builder.build().defaults |= Notification.DEFAULT_LIGHTS;
builder.setAutoCancel(true);
builder.setOngoing(true);
builder.setContentIntent(pendingIntent);
// Will show lights and make the notification disappear when the presses it
builder.build().flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
mNotificationManager.notify(1, builder.build());