Android: How do I totally remove an Activity from the Activity Stack?

狂风中的少年 提交于 2019-12-01 00:29:28

When you start application from 'Recent Application' shortcut, it will launch the last activity. So you can try to launch the application from the application list, see whether it solves your problem.

It is the correct behavior.. if you start the application through "Recent Application" it will point from the last activity. Try launching it through normal application list

For your main Activity try to set the lauch mode as "singleInstance" in the AndroidManifest file. for second activity set "Finish On Task launch" to true.

In Second scenario i think activity stack is empty as app is closed . so now you are starting activity2 , means this is the only activity in stack . now desired back behavior can be possible by overriding onbackpress and start activity1 if its second scenario .

you can call your second activity with the flag set no history like this,

intent1.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

This has worked for me several times.

Read from the Android Doc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!