在Android中点击通知时,应用程序无法启动(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);I am trying to s4 model so where run but in lollipop version,it isn't working.
My code:
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
Corrected Code
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);here: http://developer.android.com/reference/android/app/PendingIntent.html#getActivity%28android.content.Context,%20int,%20android.content.Intent,%20int%29
更多推荐
发布评论