I have a custom AsyncTaskLoader that performs a search based on some query text entered into an ActionBar search:
class SearchLoader extends AsyncTaskLoader<List<String>> {
private static final String TAG = SearchLoader.class.getName();
private List<String> data;
private String query;
private DataStore dataStore;
public SearchLoader(Context context, DataStore dataStore, String query) {
super(context);
this.dataStore = dataStore;
this.query = query;
}
@Override
public List<String> loadInBackground() {
try {
return dataStore.find(query);
} catch (SearchException e) {
Log.e(TAG, String.format("Error performing search, query: %s", query), e);
}
return null;
}
}
I have hooked up an OnQueryTextListener to refresh the loader's data by performing a new search when the query changes:
@Override
public boolean onQueryTextChange(String newText) {
query = !TextUtils.isEmpty(newText) ? newText : null;
getLoaderManager().restartLoader(SEARCHRESULTS_LOADER, null, this);
return false;
}
I am aware that I need to call getLoaderManager().restartLoader.
However, what I am not sure about is how to set the new query text on the loader itself?
- I don't have access to the loader instance to call a setter
- The arguments of the restartLoader as far as I know are only used if a new loader needs to be created
What is the recommended way to do this?