我已经设置了我的应用程序,当它被点击时,我想知道它在程序中的位置。每次单击它时,主活动都会打开,但有时我会遇到一个bug,当单击通知时,onNewIntent(Intent intent)不会被调用。这是我的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());发布于 2013-03-27 08:48:18
尝试将标志设置为:
FLAG_ACTIVITY_CLEAR_TOP而不是
FLAG_ACTIVITY_SINGLE_TOPhttps://stackoverflow.com/questions/15648309
复制相似问题