gpt4 book ai didi

android - 如何提取 AsyncTask 的返回值?

转载 作者:太空宇宙 更新时间:2023-11-03 12:58:31 25 4
gpt4 key购买 nike

<分区>

我在我的应用程序中使用 http GET 方法检索数据。任务完成后,我希望在我的 mainActivity 中显示返回值(目前我的应用程序中只有 1 个 Activity )

这是我的 asyncTask 类:

class getAsync extends AsyncTask<String,Void,String> {
String ret;
@Override
protected String doInBackground(String... params) {
String url = params[0];
myGetReq myget = new myGetReq();
ret = myget.get(url);
Log.d("[RETURN STATUS]",ret);
return ret;
}
}

在我的主要 Activity 中,我按以下方式使用它:

getAsync get = new getAsync();
get.execute(url);
statText.setText(get.ret);

其中 statText 是我的 Activity 窗口中的文本。它保持空白,即使我很难在 logcat 中看到响应的主体。如何将这些数据正确地传送回我的 Activity ?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com