问题描述
我的问题是一样的,因为这Instance活动的变量未在onPostExecute的AsyncTask或如何设置从AsyncTask的数据返回到主UI线程但我想将数据发送回相同的调用活动。犯规startActivity的意图总是重新启动活动
my issue is the same as thisInstance variable of Activity not being set in onPostExecute of AsyncTask or how to return data from AsyncTask to main UI threadbut 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);
}
这篇关于我如何将数据发送回从onPostExecute在AsyncTask的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!