0

I want to use two type asynctaskloader in one FragmentActivity.

class MyLoader1 extends AsyncTaskLoader<String>{}
class MyLoader2 extends AsyncTaskLoader<Integer>{}

I write as follows. but it compile error.

public class MyActivity extends FragmentActivity 
               implements LoaderCallbacks<String>, LoaderCallbacks<Integer>{}

Please show me answer with easy sample code.


Thanks so much.

  • possible duplicate of [How to make a Java class that implements one interface with two generic types?](http://stackoverflow.com/questions/1297972/how-to-make-a-java-class-that-implements-one-interface-with-two-generic-types) – hjpotter92 Mar 25 '13 at 16:39

1 Answers1

1

As hjpotter92 mentions, this is how Java handles generics. In this case, I would just suggest using anonymous classes as indicated in hjpotter92's link.

public class MyActivity extends FragmentActivity {
     private LoaderCallbacks<String> mLoaderCallbackString = new LoaderCallbacks<String>() {
           ...
     };

     private LoaderCallbacks<Integer> mLoaderCallbackInteger = new LoaderCallbacks<Integer>() {
           ...
     };
}

Then for each loader, you just pass the correct LoaderCallbacks object

kwazi
  • 592
  • 5
  • 8