A
作为调度器。当您想从D
启动B
并在过程中完成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));
}
}
onResume()
,因为另一个Activity将被启动。但是也有可能会调用。你可以添加一些日志来自己查看。不过我认为这不是需要担心的效率问题。 - David Wasser我不知道你是如何调用B、C和D的,或者传递了哪些数据,但如果你想要的话,在调用D时可以关闭C。
在C中启动D时,你可以这样做:
Intent intent = new Intent(this, D.class);
startActivity(intent);
finish();
完成后会启动D并关闭C。
如果没有更多信息,这只是一次无法确定的尝试。