如何从主线程中的asyncTask返回结果。
问题描述:
当我调用 asyncktaskclass.execute()
方法时,就在此行之后我想从asynck任务类的post execute方法中获取结果,这里代码段
When i call asyncktaskclass.execute("")
method , just after this line i want to get result back from the post execute method of asynck task class , here the code snippet
public void method()
{
String val;
new BackgroundTask.execute("");
//// here i want result back from this Back Ground task class immediately without making main thread sleep/////
Log.v("value coming from asyncktask class",val);
/////the problem is this val value is comming null,because log.v line executes before than post execute methd ....////
plz帮帮我解决这个问题....
谢谢
plz help me to resolve this issue....
thanks
答
首先我添加了一些格式来你的问题。现在它是可读的。
您应该查看参考: AsyncTask参考 [ ^ ] @ developer.android.com/reference
并查看Lars Vogel的精彩教程:
使用处理程序和AsyncTask和加载程序进行Android后台处理 - 教程 [ ^ ] @ Vogella.com
First of all I added some format to your question. Now it's readable.
You should check the Reference: AsyncTask Reference[^] @ developer.android.com/reference
and take a look at the great tutorials of Lars Vogel for this:
Android Background Processing with Handlers and AsyncTask and Loaders - Tutorial[^] @ Vogella.com
你好,
创建一个扩展AsyncTask的类,例如,
Hello,
Create one class that extends AsyncTask like,
public class QuestionHelper extends AsyncTask<String, String, ArrayList<HashMap<String, String>>>
public QuestionHelper(Context ctx)
{
this.ctx = ctx;
}
然后在其他课程或活动中,这样去
and then in other class or activity, go like this
ArrayList<HashMap<String, String>> QuestionsList = new QuestionHelper(getApplicationContext()).execute().get();;