3

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?

Community
  • 1
  • 1
Grace Huang
  • 5,355
  • 5
  • 30
  • 52
  • 2
    why will the ID not work in your case? – tyczj Sep 07 '13 at 01:00
  • Because the types are different, one is List, the other one is BigInteger. If i can use ID, how should i write the onCreateLoader function and other functions? – Grace Huang Sep 07 '13 at 05:28

1 Answers1

2

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.

Krylez
  • 17,414
  • 4
  • 32
  • 41
  • thanks! i also found out some code example here in one of the comments (http://www.androiddesignpatterns.com/2012/08/implementing-loaders.html) – Grace Huang Sep 07 '13 at 05:59