簡體   English   中英

我無法調試此AsyncTasc

[英]I am not able to debug this AsyncTasc

我在這個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) {}

我究竟做錯了什么?

您正在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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM