我无法调试此AsyncTask

时间:2014-09-12 18:43:28

标签: android

我在此AsyncTask中设置了断点,

我放了android:debuggable="true"

我添加了android.os.Debug.waitForDebugger();

但是调试器(Eclipse)仍然不会进入......

class DownloadWebpageTask extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... urls) {
    android.os.Debug.waitForDebugger();
    try {
        Log.e("","Sono in doibacground di DownloadWebpageTask");
        return downloadUrl(urls[0]);
    } catch (IOException e) {
        return null;
    }
}

此AsyncTask由以下AsyncTask

调用
public class DownloadGelaterieAsyncTask extends AsyncTask<Void, Void, ArrayList<Gelateria>> {

    @Override
    protected ArrayList<Gelateria> doInBackground(Void... params) {
            try {
                Log.e("i di doInBackground di DownloadGelaterieAsyncTask", Integer.toString(i));
                gelaterie = new DownloadWebpageTask()
                .execute( "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=45.4667,9.1833&radius=10000&language=Italian&keyword=gelateria&key=XXXXXXXXXXX"
                                ).get();

            } catch (Exception e1) {}

我做错了什么?

1 个答案:

答案 0 :(得分:3)

您正在AsyncTask内拨打AsyncTask。这不会按原样运作。所有AsyncTask都安排在同一个主题上,因此嵌套的AsyncTask不会被执行,直到第一个完成 - 您只是锁定了您的应用。

只需重构您的第一个AsyncTask,如下所示:

public class DownloadGelaterieAsyncTask extends AsyncTask<Void, Void, ArrayList<Gelateria>> {

    @Override
    protected ArrayList<Gelateria> doInBackground(Void... params) {
            try {
                Log.e("i di doInBackground di DownloadGelaterieAsyncTask", Integer.toString(i));
                gelaterie = downloadUrl( "https://..." );

            } catch (Exception e1) {}

无需在AsyncTask内嵌套AsyncTask