我如何将数据发送回从onPostExecute在AsyncTask的?如何将、数据、AsyncTask、onPostExecute

由网友(温如暖风)分享简介:我的问题是一样的,因为这Instance活动的变量未在onPostExecute的AsyncTask或如何设置从AsyncTask的数据返回到主UI线程但我想将数据发送回相同的调用活动。犯规startActivity的意图总是重新启动活动my issue is the same as this Instance...

我的问题是一样的,因为这 Instance活动的变量未在onPostExecute的AsyncTask或如何设置从AsyncTask的数据返回到主UI线程 但我想将数据发送回相同的调用活动。犯规startActivity的意图总是重新启动活动

my issue is the same as this Instance variable of Activity not being set in onPostExecute of AsyncTask or how to return data from AsyncTask to main UI thread but i want to send the data back to the same calling activity. Doesnt startActivity for intents always restart the activity

推荐答案

在选择是使用监听器,在那里你创建一个接口,你的活动implents,是这样的:

On option is to use listeners, where you create an interface that your activity implents, something like:

public interface AsyncListener {
    public void doStuff( MyObject obj );
}

这样的话,如果你继承AsyncTask的,很容易添加这个监听器,那么在onPostExecute(),你可以这样做:

That way, if you're subclassing AsyncTask, it is easy to add this listener, then in onPostExecute(), you could do something like:

protected void onPostExecute( MyObject obj ) {
   asyncListener.doStuff(obj);
}
阅读全文

相关推荐

最新文章