首页 > 移动平台 > 详细

android中使用notification的时候,点击home键,再从通知选项中返回点击home键前那个activity

时间:2014-11-28 19:47:07      阅读:332      评论:0      收藏:0      [点我收藏+]

为了方便新手,虽然很简单,但是我看园内没人写。。。所以就。。。(我也是新手~)

 

其实就是利用activity栈的原理....

在mainactivity的onCreat()中写:

 

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(R.drawable.ic_launcher,
                "Hello,there!", System.currentTimeMillis());
        notification.flags = Notification.FLAG_AUTO_CANCEL;

Intent intent
= new Intent(this, NotWorkActivity.class);//注意这里!!!
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(this, R.string.app_name, intent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(this, "Hello,there!", "Hello,there,I‘m john.", contentIntent); notificationManager.notify(0, notification);


这样每次启动程序都会产生一个通知;

注意那个NotWorkActivity的代码~~如下:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//就一句话!!
        this.finish();
    }

每次都退一个栈,栈顶变成上一个activity。。


然后其他activity什么都不用管,

android:launchMode="singleTask"

就可以正常运行了~~

欢迎老手有更好的方法。。。

 

android中使用notification的时候,点击home键,再从通知选项中返回点击home键前那个activity

原文:http://www.cnblogs.com/Vincent0013/p/4129104.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!