How to pass params to Android AsnycTaskLoader

4k views Asked by At

I'm trying to pass params into a AsyncTaskLoader. How do I do that?

Currently, I'm putting what I need to pass in in a separate static class. Anyway around this?

public class NewsAsyncTaskLoader extends AsyncTaskLoader<List<Content>> {

    private static final DbHelper dbHelper = DbHelperFactory.getDbHelper();

    public FeedAsyncTaskLoader(Context context) {
        super(context);
    }

    @Override
    public List<Content> loadInBackground() {
        List<Content> contents = DbHelper.getStream(FeedSections.getInstance().getCurrentSection());

        feed.setContents(contents);

        return feed;
    }
}
1

There are 1 answers

2
ianhanniballake On BEST ANSWER

Pass additional parameters into your constructor:

public FeedAsyncTaskLoader(Context context, String moreInfo) {
    super(context);
    // Do something with moreInfo
}