简体   繁体   中英

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. When I press home key and re-launch app via notification, task B goes in background and task A comes foreground. 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. But I want to clear task B when app is relaunched via notification. I tried affinity, reparenting, noHistory and noRecents flags for root activity of task B but it didn't work. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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