为了账号安全,请及时绑定邮箱和手机立即绑定

我的问题是这样的:请看下面具体情况

我的问题是这样的:请看下面具体情况

MYYA 2022-09-19 18:14:29
我写了一个service  ,service产生了通知,在状态栏中显示。 我期望点击通知图标后,打开我所期望的activity.但是现在,  每次点击通知图标  打开的都是MainActivity  (就是启动服务的那个主Activity),除非我把MainActivity退出,  才会打开我期望的activity请哪位帮忙,谢谢!!显示通知的代码如下:public void showNotification(String message) {Intent intent = new Intent();intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);NotificationInfo n = this.parser.parseNotificationInfo(message);Bundle bundle = new Bundle();bundle.putString("UNREAD_MESSAGE", "UNREAD_MESSAGE");intent.putExtras(bundle);intent.setClass(this, n.getNotifyActivityClass());intent.putExtra(PushConsts.PARAM_FROM_SERVICE, true);Notification notification = new Notification(n.getIcon(), message,System.currentTimeMillis());PendingIntent contentIntent = PendingIntent.getActivity(this, 0,intent, 0);notification.setLatestEventInfo(this, n.getTitle(), n.getContent(),contentIntent);mNM.notify(n.getId(), notification);}
查看完整描述

1 回答

?
守候你守候我

TA贡献1802条经验 获得超10个赞

  1. public static void sendNotify(Context context,Class<? extends BaseActivity> target){  

  2.         NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);     

  3.         Notification n = new Notification(R.drawable.noti_title_icon, "收到新通知", System.currentTimeMillis());    

  4.         n.flags = Notification.FLAG_AUTO_CANCEL;       

  5.         n.defaults = Notification.DEFAULT_ALL;  

  6.           

  7.         Intent i = new Intent(context,target);  

  8.         i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);  

  9.         PendingIntent pi = PendingIntent.getActivity(context, 0, i,  

  10.                 PendingIntent.FLAG_UPDATE_CURRENT);  

  11.         n.setLatestEventInfo(context, "收到新通知,请点击查看","",pi);  

  12.         nm.notify(R.string.app_name, n);  

  13.     }  


查看完整回答
反对 回复 2022-09-21
  • 1 回答
  • 0 关注
  • 209 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号