In your scenario I will recommend you to use ForceLoadContentObserver which you can bind with a URI to the ContentResolver. Like this:
class SearchLoader ....
ForceLoadContentObserver contentObserver = new ForceLoadContentObserver();
....
@Override
public void onStartLoading() {
if (cacheResult == null || takeContentChanged()) { // This will see if there's a change notification to observer and take it.
onForceLoad();
} else {
deliverResult(cacheResult);
}
}
@Override
public Result loadInBackground() {
Result result = loadResult();
// notification uri built upon Result.BASE_URI so it receives all notifications to BASE_URI.
getContext().getContentResolver().registerContentObserver(result.getNotificationUri(), true, contentObserver);
}
@Override
public void onReset() {
// ... Do your clean stuff...
getContext().getContentResolver().unregisterContentObserver(contentObserver);
}
...
}
So you can notify your change everywhere by using:
context.getContentResolver().notifyChanged(Result.BASE_URI, null);
Even when the activity holding the loader is in the background or not possible to deliverResult. And you don't need to get loaders' instances.
All the notification is around Uri of object. Uri is a powerful representation of data in Android.
But I do have my confusion as well. In this scenario, both your approach and my approach assumes a content changes means loading more data. But what if you do need to reload all the data? What kind of notification you will use?