user2195466
user2195466

Reputation: 1

how does implement multiple types asynctaskloader

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.

Upvotes: 0

Views: 1043

Answers (1)

kwazi
kwazi

Reputation: 592

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

Upvotes: 1

Related Questions