Question

Now I want to create several AsyncTaskLoaders with different types.

One could be:

public Loader<List<Category>> onCreateLoader(int id, final Bundle args) {
    ...
}

The other one could be:

public Loader<BigInteger> onCreateLoader(int id, final Bundle args) {
    ...
}

I read about the post LoaderManager with multiple loaders: how to get the right cursorloader, but simply checking the ID will not fit my case.

Should I just create two sets of implemented methods in the activity to support these two loaders?

Was it helpful?

Solution

You don't have to have your fragment inherit from the Callbacks, it's just convenient in the simplest case. When you have different Loader types, you'll need to create a local Callbacks implementation for each type. Because of type erasure, this is the only way to use multiple loader types without an ugly mess of type checking and casting. The callbacks will be members of your fragment and you'll pass these into the initLoader() methods.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top