问题描述
好了说,你使用的应用程序,你打开了一个新的活动,然后打开了一个,就可以结束活动您通过使用结束();
和你的背一个活动,但你怎么能回去两项活动,所有的方式回到第一个?我知道,你可以使用:
Okay say your using a app, and you opened a new activity and then opened another, you can end the activity your on by using finish();
and your back one activity, but how can you go back two activities, all the way back to the first one? I know you could use:
Intent savedGameIntent = new Intent(v.getContext(), firstclass.class);
v.getContext().startActivity(savedGameIntent);
但是,这是最好的方式做到这一点?
But is that the best way to do it?
推荐答案
使用该标志Intent.FLAG_ACTIVITY_CLEAR_TOP。
Use the flag Intent.FLAG_ACTIVITY_CLEAR_TOP.
Intent intent = new Intent(this,A.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
从文档:
如果设置,并且活动被启动已经在当前任务中运行,然后代替启动该活动的一个新实例,所有的在其上的其他活动将被关闭,此意图将被传递到的(现在的顶部)老年活动作为一个新的意图。
那么有效,如果你有一个 - > B - > C,你打算到A与该标志设置,B和C将关闭
So effectively, if you have A -> B -> C, and you intent to A with that flag set, B and C will close.
这篇关于完成()的活性两次的Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!