Android 消息通知栏返回正在运行的Activity

NotificationManager barmanager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notice = new Notification(android.R.drawable.stat_notify_chat,
                          "服务器发来信息了",System.currentTimeMillis());
notice.flags=Notification.FLAG_AUTO_CANCEL;
Intent appIntent = new Intent(Intent.ACTION_MAIN);
appIntent.addCategory(Intent.CATEGORY_LAUNCHER);
appIntent.setComponent(new ComponentName(this.getPackageName(), 
                       this.getPackageName() + "." + this.getLocalClassName()));
appIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|
                   Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);//关键的一步,设置启动模式
PendingIntent contentIntent =PendingIntent.getActivity(this, 0,appIntent,0);
notice.setLatestEventInfo(this,"通知","信息:"+msg, contentIntent);
barmanager.notify(STATUS_BAR_ID,notice);

posted @ 2017-03-20 15:59  vegatate  阅读(705)  评论(0编辑  收藏  举报