由网友(抱歉我历史不好不知曾经)分享简介:我想叫活动之后的 onPostExecute 方法我的AsyncTask 。你知道我怎么能做到这一点?I would like to call an Activity method after the onPostExecute of my AsyncTask.Do you know how I can do t...
我想叫活动
之后的 onPostExecute
方法我的AsyncTask
。
你知道我怎么能做到这一点?
I would like to call an Activity
method after the onPostExecute
of my AsyncTask
.
Do you know how I can do that?
我要在 sendSMS(字符串phoneNumber的,字符串消息)来调用
的方法 onPostExecute
。
推荐答案
一种方法是通过活动的一个实例
到 PostTask
的构造,是这样的:
One way is to pass an instance of the Activity
through PostTask
constructor, something like:
private class PostTask extends AsyncTask<String, Integer, String>
{
private AsyncBigCalculActivity activity;
public PostTask(AsyncBigCalculActivity activity)
{
this.activity = activity;
}
// ...
}
和创造的 PostTask
实例,通过活动的实例:
and on creating the PostTask
instance, pass the activity instance:
new PostTask(this).execute();
现在,你可以调用 sendSMS()
从内部 PostTask
,如:
Now you can invoke sendSMS()
from within PostTask
, like:
activty.sendSMS(...);
另外请注意,如果您正在定义的 PostTask
作为activty内部的私有类,那么你可以调用 sendSMS()
这样的:
Also note that if you are defining the PostTask
as a private class inside the activty, then you can invoke sendSMS()
like:
AsyncBigCalculActivity.this.sendSMS(...);
相关推荐
最新文章