【发布时间】:2018-09-23 15:20:17
【问题描述】:
我想使用 Android Native 运行两个连接:
public class MyPublicClass extends AppCompatActivity {
这是第一堂课
private class GetNextQuestionIndex extends AsyncTask<String, Void, Void> {
//some code
protected Void doInBackground(String... params) {
URL url = new URL("url1");
//some code to initialize connection and get the output
MyPublicClass.this.runOnUiThread(new Runnable() {
@Override
public void run() {
mytxtview.setText(output1)
System.out.println("1");
progress.dismiss();
}
});
这是第二课
private class GetLibelleOfQuestion extends AsyncTask<String, Void, Void> {
//some code
protected Void doInBackground(String... params) {
URL url = new URL("url2");
//some code to initialize another connection and get another output
MyPublicClass.this.runOnUiThread(new Runnable() {
@Override
public void run() {
mytxtview.setText(output2)
System.out.println("2");
progress.dismiss();
}
});
}//the end of the public class
但是当我运行我的代码时它给了我
2 1
我怎样才能得到
1 2
?
这意味着在运行GetLibelleOfQuestion之前执行GetNextQuestionIndex的运行
【问题讨论】:
-
你如何为每个任务调用
execute( )?
标签: android multithreading url