英文:
How to kill previous instances of a particular activity from call stack
问题
当我在活动C中按下重置按钮时,我想要销毁活动B的先前实例,以便我的堆栈变为 [A | C | B]。我不能在转到活动C时完成活动B,因为我可能需要返回到B。
英文:
My activity flow is like A->B->C->B,
When I press reset button in activity C I go to Activity B
Button reset=(Button) findViewById(R.id.button3);
reset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view){
Intent intent = new Intent(C.this, B.class);
startActivity(intent);
finish();
}
});
But, I want to destroy the previous instance of activity B when I press reset button in activity C, so that my stack becomes
[A | C| B].
I can't finish Activity B while going to Activity C as I might have to come back to B.
答案1
得分: 0
你可以使用广播完成命令,并在活动中接收到一个完成信号时,结束该操作。
英文:
you can use broadcast finish order and when receive in activity a finish that
答案2
得分: 0
添加FLAG_ACTIVITY_CLEAR_TOP,当你从c启动B时,它会删除不需要的B。
Intent i = new Intent(this, B.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
英文:
add FLAG_ACTIVITY_CLEAR_TOP when you start B form c it will deleted the unneeded B
Intent i = new Intent(this, B.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论