您的位置:首页 > 其它

Notification返回到当前正在运行的Activity

2011-10-02 06:41 302 查看
Notification notification=...

NotificationManager nm=...

//

Intent notificationIntent = new Intent(this,this.getClass());

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);

nm.notify(1, notification);

new Intent(this,this.getClass())保证了点击通知栏里的通知可以回到该Activity

但是,假如该Activity还在后台运行,并没有运行,通知事件响应后,系统会自动结束该Activity,然后再重新启动Activity,这不是我们要的。

解决方法为:在manifest.xml文件中找到该Activity,添加属性android:launchMode="singleTask“。这个属性很明显,就是只允许有一个该Activity运行,如果正在运行,则只能切换到当前运行的Activity,而不能重新启动Activity。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: