无法将响应从AsyncTask发布到MainActivity

无法将响应从AsyncTask发布到MainActivity,第1张

无法将响应从AsyncTask发布到MainActivity

错了 您不应创建活动类的实例。

 MainActivity main = new MainActivity();

活动由开始

startActivity

您可以将asynctask设为活动类的内部类,并在其中更新ui

onPostExecute

或使用界面

如何从AsyncTask返回布尔值?

编辑

   new onbuttonclickHttpPost(ActivityName.this).execute(params);

在你的任务中

  TheInterface listener;

在施工中

  public onbuttonclickHttpPost(Context context){    listener = (TheInterface) context;    c= context;}

介面

  public interface TheInterface {    public void theMethod(String result);     }

在onPostExecute中

    if (listener != null)   {      listener.theMethod(result);      }

在您的活动类中实现接口

     implements OnbuttonclickHttpPos.TheInterface

实施方法

     @Override     public void theMethod(STring result) {   // update ui using result     }


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5489391.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存