问题
I have a problem with AsyncTaskLoader
. When app is starting, it works fine. Then I call onRefreshStarted
, and again all is good. But if change orientation, AsyncTaskLoader
start processing loadInBackground
, but onLoadFinished
is never called. What is wrong?
Here's simplified SherlockFragment:
public class MyFragment extends SherlockFragment implements LoaderCallbacks<Object> {
PullToRefreshLayout Rl;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (Rl == null) {
Rl = (PullToRefreshLayout) inflater.inflate(
R.layout.friends_fragment_rpc, null);
getData();
} else {
ViewGroup parent = (ViewGroup) Rl.getParent();
parent.removeView(Rl);
getData();
}
setRetainInstance(true);
return Rl;
}
private void getData() {
loaderBndl = new Bundle();
loaderBndl.putString(RequestLoader.ARGS_URL, url);
getActivity().getLoaderManager().initLoader(LOADER_ID, loaderBndl, this)
.forceLoad();
}
@Override
public Loader<Object> onCreateLoader(int id, Bundle args) {
Loader<Object> loader = null;
if (id == LOADER_ID) {
loader = new RequestLoader(getActivity(), args);
}
return loader;
}
@Override
public void onLoadFinished(Loader<Object> loader, Object result) {
Log.d(TAG, "onLoadFinished");
}
@Override
public void onRefreshStarted(View view) {
getData();
}
}
and AsyncTaskLoader:
public class RequestLoader extends AsyncTaskLoader<Object> {
public RequestLoader(Context context, Bundle args) {
super(context);
if (isDebug)
Log.d(TAG, "create RequestLoader");
...
}
@Override
public Object loadInBackground() {
if (isDebug)
Log.d(TAG, "loadInBackground");
Object requestResult = null;
...
return requestResult;
}
}
回答1:
The problem is solved - Sherlock Fragment should use SupportLoaderManager .
来源:https://stackoverflow.com/questions/24564816/asynctaskloader-doesnt-call-onloadfinished