当用户点击按钮我调用这个方法,我想做多个AsyncTask调用上传不同的东西。 (一些文字,照片,然后是视频)。我执行第一个方法罚款(文本),但然后我不能开始下一个调用/执行(backgroundTask.execute),因为第一个没有完成。多次执行AsyncTask? [Android]
我的问题:
我怎么能说我的AsyncTask,所以我可以一次上传的一切吗? (点击一个按钮)
我想有它设置等等onPostExecute我更新一个变量,然后在这个方法中,我有一个简单的,如果看到检查语句,如果该变量已经改变,但它显然不是招”工作。
我是否应该等待每个人完成开始下一个或我应该在同一时间?
的Android代码:
public void UploadEverything(String encodedImage){
//Gets the email form the user
SharedPreferences UserCredentials = getSharedPreferences("UserCredentials", Context.MODE_PRIVATE);
ProductOwnerEmail = UserCredentials.getString("UserEmail", "");
String method = "ProductDetails";
BackgroundTask backgroundTask = new BackgroundTask(this);
backgroundTask.execute(method, ProductOwnerEmail, ProductName, Seller_Category, ProductKeyCode, DescriptionPoint, DescriptionPoint2, DescriptionPoint3);
if (BackgroundTask.DetailsUploaded.equals("true")) {
String PhotoMethod = "Photo";
//BackgroundTask backgroundTask = new BackgroundTask(this);
backgroundTask.execute(PhotoMethod, ProductOwnerEmail, ProductName, encodedImage);
}
if(BackgroundTask.PhotoUploaded.equals("true")) {
String SevenSecVideoMethod = "7secVideo";
//BackgroundTask backgroundTask = new BackgroundTask(this);
backgroundTask.execute(SevenSecVideoMethod, ProductOwnerEmail, ProductName, String.valueOf(selectedPath));
}
Toast.makeText(SellerHomePage.this, "Product has been uploaded!", Toast.LENGTH_SHORT).show();
}
你是什么意思你“不能开始下一个”?有没有崩溃?什么阻止你? –
完成后,无法再次启动同一个线程。您需要创建AsyncTask的另一个对象并调用它的execute方法。 –
为什么你要多次调用AsyncTask,如果你可以一次发布所有东西? – Apurva