我可以为一个Activity的结果启动同一类的多个活动吗?

时间:2015-03-25 14:24:07

标签: java android multithreading android-intent

我有一个类,我们将其命名为IntentStartingThread,其属性为Activity contextActivityIntents启动,Bundle data - 数据,传递给已启动的Intentint resultCode,这是已启动意图的结果代码。

IntentStartingThread的run()基本上是

....
Intent resultActivity = new Intent(context, ResultActivity.class);
resultActivity.putExtra("data", data);
context.startActivityForResult(resultActivity, resultCode);

在课堂上,我要命名CallingActivity extends Activity我有常量

private static final int FIRST_REQUEST_CODE = 456;
private static final int SECOND_REQUEST_CODE = 457;
private static final int THIRD_REQUEST_CODE = 458;

IntentStartingThread个对象thread1thread2thread3

在一个线程中,从onCreate()方法运行,其中我有一个变量Activity activity,它指向CallingActivity,我调用

thread1 = new IntentStartingThread(activity, someData, FIRST_REQUEST_CODE);
thread2 = new IntentStartingThread(activity, someData, SECOND_REQUEST_CODE);
thread3 = new IntentStartingThread(activity, someData, THIRD_REQUEST_CODE);

thread1.run();

CallingActivity.onActivityResult()看起来如下:

if (requestCode == FIRST_REQUEST_CODE){
    thread2.run();
    //doStuff
} else if (requestCode == SECOND_REQUEST_CODE) {
    thread3.run();
    //doMoreStuff
} else if (requestCode == THIRD_REQUEST_CODE) {
    //doTheLastStuff
}

thread1运行活动是可以的,thread2正在运行,我似乎没有从第二次运行结果活动时收到结果 - 它没有进入onActivityResult ()。

0 个答案:

没有答案