简体   繁体   English

如何在Android中清除后台活动任务堆栈?

[英]How to clear background activity task stack in Android?


My app is having task A with 4 activities as root task and on it task B is there containing 2 activities. 我的应用程序正在执行任务A,其中4个活动作为根任务,其中任务B包含2个活动。 When I press home key and re-launch app via notification, task B goes in background and task A comes foreground. 当我按下主页键并通过通知重新启动应用程序时,任务B进入后台,任务A进入前台。 So now app state is task A upon task B. So when I press back key, activities Y and X in task B are displayed. 所以现在app状态是任务B上的任务A.所以当我按下后退键时,显示任务B中的活动Y和X. But I want to clear task B when app is relaunched via notification. 但是,当通过通知重新启动应用程序时,我想清除任务B. I tried affinity, reparenting, noHistory and noRecents flags for root activity of task B but it didn't work. 我为任务B的根活动尝试了affinity,reparenting,noHistory和noRecents标志,但是它没有用。 Is there any way to do this? 有没有办法做到这一点?
Thanks. 谢谢。

Intent intent = new Intent(this, classObject);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);

Hope this will work for you. 希望这对你有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM