singleTask and singleInstance not respected when using PendingIntent?

烈酒焚心 提交于 2019-12-05 12:39:45

Your problem is due to the use of TaskStackBuilder. This code is causing your problem:

Intent activityIntent = new Intent( this,
                                MyActivity.class );
TaskStackBuilder stackBuilder = TaskStackBuilder.create( this );
stackBuilder.addParentStack( MyActivity.class );
stackBuilder.addNextIntent( activityIntent );
PendingIntent resultingActivityPendingIntent =
         stackBuilder.getPendingIntent(REQUEST_CODE,
         PendingIntent.FLAG_UPDATE_CURRENT );

When you use TaskStackBuilder this way, it sets additional flags in the generated Intents that cause the task to be reset (all Activities in the task are destroyed) before your Activity gets launched.

Instead use:

Intent activityIntent = new Intent( this,
                                MyActivity.class );
PendingIntent resultingActivityPendingIntent =
         PendingIntent.getActivity(this, REQUEST_CODE,
             activityIntent, PendingIntent.FLAG_UPDATE_CURRENT );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!