Start Activity clearing top in Android

廉价感情. 提交于 2019-12-30 12:36:15

问题


I have the following Activities in my stack:

A , B , C, D 

I want to relaunch B in order to get this stack:

A , B'

Where B' is a new B instance (not the old receiving a onNewIntent callback, how can I do it?

By the way I'm using a

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

when launching the B activity but this way the onNewIntent is called instead of start a new instance


回答1:


Use android:noHistory=true in manifest file for particular activity to clear.Hope this might solve your issue.




回答2:


here when you use this code the its take you on activity B. in B you Press backbutton the its take you on A.

Intent fromDtoB = new Intent(this,B.class);
fromDtoB.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(fromDtoB);

FLAG_ACTIVITY_CLEAR_TASK: If set in an Intent passed to Context.startActivity(), this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started.

FLAG_ACTIVITY_CLEAR_TOP: If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.



来源:https://stackoverflow.com/questions/16211678/start-activity-clearing-top-in-android

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