我有一个活动层次结构,我有一个按钮,允许我从活动D转到活动B。
问题是,从D到B会把C留在后台,所以如果我做A->C->D->B,然后按后退,它会把我发送到C,而不是A(这就是我想要的)。
当我点击B中的按钮时,是否有一种删除C的方法,还是有某种解决办法?
发布于 2015-11-24 09:57:43
考虑使用A
作为调度器。当您希望从B
启动D
并在此过程中完成C
时,请使用D
执行此操作
// Launch A (our dispatcher)
Intent intent = new Intent(this, A.class);
// Setting CLEAR_TOP ensures that all other activities on top of A will be finished
// and setting SINGLE_TOP ensures that a new instance of A will not
// be created (the existing instance will be reused and onNewIntent() will be called)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
// Add an extra telling A that it should launch B
intent.putExtra("startB", true);
startActivity(intent);
在A.onNewIntent()
中这样做:
@Override
protected void onNewIntent(Intent intent) {
if (intent.hasExtra("startB")) {
// Need to start B from here
startActivity(new Intent(this, B.class));
}
}
发布于 2015-11-23 21:06:58
我不知道调用B、C和D的具体方式,也不知道数据是如何传递的,但如果需要,可以在调用D时关闭C。
在C中,当启动D时,您可以这样做:
Intent intent = new Intent(this, D.class);
startActivity(intent);
finish();
结束将在开始D之后关闭C。
再一次,没有太多的信息,这只是一个在黑暗中拍摄。
https://stackoverflow.com/questions/33879719
复制相似问题