[英]App is not launching when tapped on notification in Android
我正在尝试s4模型,以便在哪里运行,但在棒棒糖版本中,它无法正常工作。
我的代码:
Intent myIntent = new Intent(CheckinService1.this,
Main1.class);
myIntent.putExtra("check", "check");
sp.putCheckin(CheckinService1.this, "check");
PendingIntent pendingIntent = PendingIntent
.getActivity(CheckinService1.this, 0, myIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
myNotification.defaults |= Notification.DEFAULT_SOUND;
myNotification.defaults |= Notification.DEFAULT_VIBRATE;
myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
myNotification.setLatestEventInfo(context,
notificationTitle, notificationText,
pendingIntent);
notificationManager.notify(MY_NOTIFICATION_ID,
myNotification);
更正的代码
Intent myIntent = new Intent(CheckinService1.this,
Main1.class);
myIntent.putExtra("check", "check");
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP);
sp.putCheckin(CheckinService1.this, "check");
PendingIntent pendingIntent = PendingIntent
.getActivity(CheckinService1.this, 0, myIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
myNotification.defaults |= Notification.DEFAULT_SOUND;
myNotification.defaults |= Notification.DEFAULT_VIBRATE;
myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
myNotification.setLatestEventInfo(context,
notificationTitle, notificationText,
pendingIntent);
notificationManager.notify(MY_NOTIFICATION_ID,
myNotification);
此处: http : //developer.android.com/reference/android/app/PendingIntent.html#getActivity%28android.content.Context,%20int,%20android.content.Intent,%20int%29
尝试添加:
myNotification.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.