点击Notification正确回调到之前已经放置在后台的Task中的对应Activity,而不是创建它的一个新实例...
生活随笔
收集整理的這篇文章主要介紹了
点击Notification正确回调到之前已经放置在后台的Task中的对应Activity,而不是创建它的一个新实例...
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);Notification notification = new Notification(R.drawable.logo_icon_16,"移動營銷", System.currentTimeMillis());Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setClass(this, BeforeLogoActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);notification.flags = Notification.FLAG_ONGOING_EVENT; // 設置常駐 FlagPendingIntent contextIntent = PendingIntent.getActivity(this, 0, intent, 0);notification.setLatestEventInfo(getApplicationContext(),"移動營銷", "", contextIntent);notificationManager.notify(R.drawable.logo_icon_16, notification);
除了 setClass 可以換成使用?setClassName 綁定,FLAG_ACTIVITY_RESET_TASK_IF_NEEDED可以不設,其他的選項都缺一不可。設置ACTION_MAIN與CATEGORY_LAUNCHER是把該Intent發給了系統對應創建程序的模塊,然后系統該模塊根據設定的包與類信息還有flags進行處理。當然所有的Intent工作原理都是這樣,只是對 ACTION_MAIN - CATEGORY_LAUNCHAR 的處理較為特殊,使得總是顯示Task棧頂的Activity而不是setClass設定的Activity類。
轉自:http://blog.csdn.net/zz_mm/article/details/8021428
轉載于:https://www.cnblogs.com/l2rf/archive/2013/04/09/3009211.html
總結
以上是生活随笔為你收集整理的点击Notification正确回调到之前已经放置在后台的Task中的对应Activity,而不是创建它的一个新实例...的全部內容,希望文章能夠幫你解決所遇到的問題。