在Android中点击通知时,应用程序无法启动(App is not launching when tapped on notification in Android)

编程入门 行业动态 更新时间:2024-10-25 23:37:50
在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

更多推荐

本文发布于:2023-08-03 16:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1393333.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   无法启动   通知   Android   notification

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!