Я создаю AsyncTaskLoader на основе http://developer.android.com/reference/android/content/AsyncTaskLoader.html. Когда я запускаю свое приложение, в соответствии с моим протоколированием приложение бесконечно колеблется между loadInBackground
и onCanceled
. Кто-нибудь знает, почему эта ошибка может произойти? Мой BroadcastReceiver основан на Proper notification of AsyncTaskLoader about data changes from background thread.AsyncTaskLoader endless onCanceled call
Вот мой метод loadInBackground:
@Override
public List<MyItem> loadInBackground() {
List<MyItem> items = createDummyData();
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(new Intent(RECEIVER_FILTER_STRING));
Log.d(TAG,”custom loader send broadcast from background and send items: "+items.size());
return items;
}
Вот мой onStartLoading
@Override
protected void onStartLoading() {
Log.d(TAG, "items loader onStartLoading");
if (null != mData) {
Log.d(TAG, "items loader onStartLoading mData not null");
//someone is calling to start the loader, so if we have data, deliver it now
deliverResult(mData);
}
if (null == mReceiver) {
Log.d(TAG, "items loader onStartLoading register receiver");
mReceiver = new LoaderBroadcastReceiver(this);
LocalBroadcastManager.getInstance(getContext()).
registerReceiver(mReceiver, new IntentFilter(RECEIVER_FILTER_STRING));
}
if (takeContentChanged() || null == mData) {
//if data has changed since the last time it was loaded or is not available, then:
Log.d(TAG, "items loader onStartLoading onChange forceLoad");
forceLoad();
}
}
Вот мой приемник
class LoaderBroadcastReceiver extends BroadcastReceiver {
private Loader loader;
public LoaderBroadcastReceiver(Loader loader) {
this.loader = loader;
}
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "loader receiver informing of oonContentChagned");
loader.onContentChanged();
}
}