2015-06-23 74 views
2

在我的應用程序中,當我調用新的RetrieveFirstThreeArtUrl()。execute()doInBackground沒有被調用..有誰知道爲什麼?此代碼是工作前幾天,所以我不知道發生了什麼事..asyncTask的doInBackground沒有被調用?

public class RetrieveFirstThreeArtUrl extends AsyncTask<String, Void, Void> { 

    static final String APIURL = "http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=2ead17554acf667f27cf7dfd4c368f15&artist=%s&album=%s"; 
    static final String APIURL_ARTIST = "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&api_key=2ead17554acf667f27cf7dfd4c368f15&artist=%s"; 


    @Override 
    public void onPreExecute() { 

     super.onPreExecute(); 
     Log.v("", "Pre"); 
    } 

    @Override 
    public Void doInBackground(String... args) { 
     Log.v("", "Background"); 


     return null; 
    } 

    @Override 
    public void onPostExecute(Void args) { 
     list = (ListView) rootView.findViewById(R.id.list); 
     adapter = new LiveAdapter(LiveStreamFragment.this.getActivity(), oslist, LiveStreamFragment.this, list); 
     list.setAdapter(adapter); 

    } 


} 
+0

執行方法連續運行AsyncTask,所以如果你已經調用它,一旦下一次將在前一次完成後啓動 –

+0

我不確定你的意思是完全是什麼...... –

+0

你能否告訴你整行代碼new RetrieveFirstThreeArtUrl()。execute()。重寫方法的訪問說明符也受保護 – TechnoBlahble

回答

1

與此

替換你的代碼中調用RetrieveFirstThreeArtUrl方法之前,寫這兩條線

static final String APIURL = "http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=2ead17554acf667f27cf7dfd4c368f15&artist=%s&album=%s"; 
static final String APIURL_ARTIST = "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&api_key=2ead17554acf667f27cf7dfd4c368f15&artist=%s"; 

而不是呼叫方法RetrieveFirstThreeArtUrl,一件事,使用protected代替public

public class RetrieveFirstThreeArtUrl extends AsyncTask<String, Void, Void> { 


    @Override 
    protected void onPreExecute() { 
     super.onPreExecute(); 
     Log.v("", "Pre"); 
    } 

    @Override 
    protected void onPostExecute(Void result) { 
     list = (ListView) rootView.findViewById(R.id.list); 
     adapter = new LiveAdapter(LiveStreamFragment.this.getActivity(), oslist, LiveStreamFragment.this, list); 
     list.setAdapter(adapter); 
    } 

    @Override 
    protected Void doInBackground(String... params) { 
     Log.v("", "Background"); 
     return null; 
    }  
} 
相關問題