[英]doInBackground of asyncTask not getting called?
In my app, when I call new RetrieveFirstThreeArtUrl().execute() doInBackground isn't getting called.. does anyone know why?在我的应用程序中,当我调用 new RetrieveFirstThreeArtUrl().execute() doInBackground 时没有被调用.. 有谁知道为什么? 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在调用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";
And than call method RetrieveFirstThreeArtUrl
, one more thing , use protected
instead of public
除了调用方法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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.