我的问题是假设我们有4个活动。
A-> B-> C-> d
。 在Activity C中,我传递了一个意图转到D,然后从D再次回到C.在从C中获取D所需的结果后,我运行异步任务,之后我必须回到B.Now我BackPress在B而不是A,活动变为
B-> C-> B-> A
这肯定是一个重复的问题,但我没有得到我的问题的正确答案。
答案 0 :(得分:0)
Store this context of activities B,C,D in a static variable like this
Activity Cprivate static C cContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_c);
cContext=this;
}
Do same thing on Activity D also and in Activity B
private static B bContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_b);
clearAllTasks();
bContext=this;
}
private void clearAllTasks() {
if(D.dContext!=null)
D.dContext.finish();
if(C.cContext!=null)
C.cContext.finish();
if(B.bContext!=null)
B.bContext.finish();
}
Like this you can clear your backstack.From Activity B it will finish all other activies.
If you are coming to Activity B without calling intent from Activity C or D you can call clearAllTasks();
in onResume()
.