我有一个类,我们将其命名为IntentStartingThread
,其属性为Activity context
,Activity
由Intents
启动,Bundle data
- 数据,传递给已启动的Intent
和int 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
个对象thread1
,thread2
和thread3
。
在一个线程中,从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 ()。