如何完成的活动,回到一个不同的位置? [英] How to finish an activity and return to a varied location?
问题描述
我的应用程序实现其伸展在3-4活动的行动。
的入口点这个过程可以从应用程序不同的活动。 (HomeActivity,各种displayActivities)。我想一旦最后一个活动成功完成后,返回到开始活动。
My application implements an action which stretch upon 3-4 activities. the entry point to this process can be from different activities in the application. (HomeActivity, various displayActivities). I want to return to the starting activity once the last activity is finished successfully.
有没有一种最佳实践的方式来做到这一点?三江源。
Is there a best practice way to do it? thankyou.
推荐答案
您可以使用一个全局静态布尔来帮助你完成这个(在本例 SomeClass.IsClosingFlow
) ,
此外,您应该定义每一项活动为标记,如果它是在流(流量=意味着它是需要被关闭的活动包的一部分)。我建议使用这个标志,如果你所有的活动正在扩大一些抽象的活动一个抽象方法(即 isActivityInFlow()
)。
You can use a global static boolean to help you with this (in the example SomeClass.IsClosingFlow
),
Plus, you should define each activity to "mark" if it's in the "flow" (flow=meaning it's part of the pack of activities that need to be closed). I recommend using this mark as an abstract method if you all your activities are extending some abstract-activity (i.e. isActivityInFlow()
).
以下code说明了这一点,
它需要在 onResume()
应用程序中的每个活动的地方:
The following code demonstrates this,
It needs to be places in onResume()
of each activity in the application:
// Check to see if we are in the process of closing activities
if (SomeClass.IsClosingFlow){
if (isActivityInFlow()){
this.finish();
}
else{
// If we got here, and we're not in the flow anymore
SomeClass.IsClosingFlow = false;
}
}
这篇关于如何完成的活动,回到一个不同的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!