gpt4 book ai didi

java - 将字符串发送到 AsyncTask

转载 作者:行者123 更新时间:2023-12-01 12:20:08 27 4
gpt4 key购买 nike

如何像传递函数一样将变量传递到 AsyncTask 中?我想用 var httpLink 做什么

private class getinternetData extends AsyncTask<String, Void, String>{

@Override
protected String doInBackground(String... params) {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(httpLink);
try{
//message.setText("333");
HttpResponse response = httpclient.execute(httpget);
//message.setText("444");
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if(statusCode == 200){
return "Could connect";
}else
return "Couldn't connect";
}catch(Exception e){
return e.toString();
}


}

最佳答案

您使用参数调用执行:

new getinternetData().execute("My string param");

那么你的httpLink就是params[0]

关于java - 将字符串发送到 AsyncTask,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26726225/

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