如何从主线程中的asyncTask返回结果。 [英] how to get result back from asyncTask in main thread.

查看:87
本文介绍了如何从主线程中的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();;


这篇关于如何从主线程中的asyncTask返回结果。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆