如何活动Ç返回到Android的活性的? [英] How activity C return to activity A in android?
问题描述
让说,有三种活性
A-> B-> C
如果我从C到B回来,我所要做的仅仅是:
在C:
onBack pressed();
和B中
保护无效的onSaveInstanceState(包outState){
.....
}
如果(savedInstanceState!= NULL){
.....
}
以上code将处理为从C到B但是,如果C到A,我应该怎么做呢?此外,如何处理,如果我想A和C之间的所有活动都destoryed当C到A?谢谢
另外,如何处理,如果我想A和C之间的所有活动都destoryed当C到A?
使用该意图国旗
意向书我=新的意图(ActivityC.this,ActivityA.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(ⅰ);
但是,如果C到A,我该怎么办?
此标志将保留所有活动
之间的堆栈,但带来的正面
意向书我=新的意图(ActivityC.this,ActivityA.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(ⅰ);
在这两种情况下,你会想完成()
在C调用后打电话到 startActivitiy()
如果你想把它删除。
您可以找到所有意图旗
的在这里,在文档
Let say there are three activity
A->B->C
If I am returning from C to B , What I have to do is simply:
In C:
onBackPressed();
And in B
protected void onSaveInstanceState(Bundle outState) {
.....
}
if (savedInstanceState != null) {
.....
}
The above code will handle the case for From C to B. However, what if C to A, what should I do? Also, how to handle if I would like all activities between A and C are destoryed when C to A? Thanks
Also, how to handle if I would like all activities between A and C are destoryed when C to A?
Use this Intent Flag
Intent i = new Intent(ActivityC.this, ActivityA.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
However, what if C to A, what should I do?
This flag will keep all Activities
in between on the stack but bring A to the front
Intent i = new Intent(ActivityC.this, ActivityA.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(i);
In either case, you will want to call finish()
on C after calling startActivitiy()
if you want it removed.
You can find all Intent Flags
Here in the Docs
这篇关于如何活动Ç返回到Android的活性的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!