Vincent.zZ

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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

 

其实就是利用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"

就可以正常运行了~~

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

 

posted on 2014-11-28 17:45  Vincent.zZ  阅读(271)  评论(0)    收藏  举报