[英]Is it possible to perform separate network thread within a same activity without wait?
I am performing two class which is extending ASyncTask
and both have different functions but because of the second
class my first class is lagging. 我正在执行两个类,这些类正在扩展ASyncTask
并且都具有不同的功能,但是由于second
类,我的第一类比较滞后。 So what i want to know is, is there any better solution to code in such a way that both of the operation will perform the task without making other operation to wait? 因此,我想知道的是,有没有一种更好的代码解决方案,使得两种操作都可以执行任务而无需等待其他操作?
Updated with code For the first call in the onCreate()
已更新代码,用于onCreate()
的首次调用
new connection().execute(); //
Some task performed by the same class called 由同一个类执行的某些任务称为
public class connection extends AsyncTask {
@Override
protected Object doInBackground(Object... arg0) {
//some operation
return value;
}
@Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);
String m = String.valueOf(o);
if (o != null) {
someoperation
} else {
edittxt.setTextColor(Color.RED);
edittxt.setText("No Internet Connection");
}
}
}
similarly i am performing the other class that i have. 同样,我正在表演另一门课。
You can create two separate threads and perform your operations. 您可以创建两个单独的线程并执行您的操作。 It will quarantine, that all operations will be performed async. 它将隔离所有操作将异步执行。
final Handler handler = new Handler();
Thread operation1 = new Thread(new Runnable() {
@Override
public void run() {
doOperation1();
handler.run(new Runnable(){
@Override
public void run() {
onPostExecute1();
}
});
}
});
Thread operation2 = new Thread(new Runnable() {
@Override
public void run() {
doOperation2();
handler.run(new Runnable(){
@Override
public void run() {
onPostExecute2();
}
});
}
});
operation1.start();
operation2.start();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.