有人可以解释如何以特定顺序从一个活动调用多个活动吗?Android:以特定顺序连续调用多个活动
其实我想调用第一个子活动(如果相应的条件为真),等待它完成,然后调用第二个子活动(如果条件允许),也等待它完成,所以上。最后,应用程序必须转到其他活动并关闭子活动被调用的活动。
问题是,应用程序一次执行所有意图,最初应该调用的活动首先出现在屏幕上。
下面是代码:
@Override
public void onResume()
{
super.onResume();
if(allocated)
{
super.onResume();
if (warEvent)
{
Intent intent = new Intent(this, War.class);
warEvent = false;
startActivity(intent);
}
if (annexEvent)
{
Intent intent = new Intent(this, Annexation.class);
annexEvent = false;
startActivity(intent);
}
if (heirEvent)
{
Intent intent = new Intent(this, Dynasty.class);
heirEvent = false;
startActivity(intent);
}
if (diseaseEvent)
{
Intent intent = new Intent(this, Disease.class);
diseaseEvent = false;
startActivity(intent);
}
if (corruptEvent)
{
Intent intent = new Intent(this, Corruption.class);
corruptEvent = false;
startActivity(intent);
}
if (catchEvent)
{
Intent intent = new Intent(this, CatchCorrupt.class);
catchEvent = false;
startActivity(intent);
}
Intent intent = new Intent(this, Coliseum.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
我想是叫战争,返回到主活动,然后调用兼并,等等,和体育馆到底应该被调用。出于某种原因,主要活动的onPause()不会被调用,并且所有intent都会立即执行,所以Coliseum首先被调用而不是War。为您的方案
为什么不使用[Fragments](https://developer.android.com/guide/components/fragments.html)? –
如何使用'startActivityForResult'和do if-else以便一次只启动一个活动? – nasch