我正在使用AsyncTasks来获取数据以响应用户按下按钮.这很好用并且在获取数据时保持接口响应,但是当我检查Eclipse调试器中发生了什么时,我发现每次AsyncTask创建一个新的(这通常是因为它们只能使用一次),正在创建一个新线程,但从未终止.
结果是大量的AsyncTask线程就坐在那里.我不确定这在实践中是否是一个问题,但我真的想摆脱那些额外的线程.
我怎么能杀死这些线程?
我使用以下类连接到我的Web服务.我想让这个异步.我怎样才能做到这一点?
package org.stocktwits.helper;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
public class RestClient{
private static String convertStreamToString(InputStream is) {
/*
* To convert the InputStream to String we use the BufferedReader.readLine()
* method. We iterate until the BufferedReader return null which means
* there's no more data to read. Each line will appended to a StringBuilder
* and returned as String. …Run Code Online (Sandbox Code Playgroud)