简体   繁体   中英

doInBackground of asyncTask not getting called?

In my app, when I call new RetrieveFirstThreeArtUrl().execute() doInBackground isn't getting called.. does anyone know why? This code was working a few days ago, so I have no idea what's going on..

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);

    }


}

Replace your code with this

before calling RetrieveFirstThreeArtUrl method, write these two lines

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";

And than call method RetrieveFirstThreeArtUrl , one more thing , use protected instead of 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;
    }       
}   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM