我正在使用一个网络服务来获取数据并将其存储在String
中。我需要使用这个String
,但我无法接受。全局变量在线程中不起作用。我使用的是传统线程 new Thread() { public void run() {
.
最佳答案
AsyncTask 示例:
public class Task extends AsyncTask<Params, Progress, String> {
// are you know how to use generic types?
protected String doInBackground(Params[] params){
// this code will run in seperate thread
String resultString;
return resultString;
}
protected void onPostExecute(String resultString){
// this code will call on main thread (UI Thread) in this thread you can update UI e.g. textView.setText(resultString);
}
}
关于java - 如何从线程获取字符串或从线程返回字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31226388/