1

I have a simple fragment, trying to implement AsyncTaskLoader in it. But i am getting one compile time error :

error: incompatible types required: Loader< List< String>> found: LoaderDrone

the error is in the onCreateLoader method. what am i missing ?

After some research i am unable to find the solution.

here is the code

 public class SubPlaceFragment extends Fragment implements LoaderManager.LoaderCallbacks<List<String>> {


 @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        getLoaderManager().initLoader(0, null, this);
        getLoaderManager().getLoader(0).startLoading();
    }


  @Override
        public Loader<List<String>> onCreateLoader(int id, Bundle args) {
            return new LoaderDrone(getActivity());
        }

        @Override
        public void onLoadFinished(Loader<List<String>> loader, List<String> data) {

        }

        @Override
        public void onLoaderReset(Loader<List<String>> loader) {

        }

        public static class LoaderDrone extends AsyncTaskLoader<List<String>> {

            public LoaderDrone(Context context) {
                super(context);
                onForceLoad();
            }

            @Override
            public List<String> loadInBackground() {
                List<String> results = null;


                return results;
            }
        }
    }

Thanks for the help :)

Manish Gupta
  • 149
  • 1
  • 5
  • 15

1 Answers1

4

Make sure you are importing the correct Loader class.

If you're using a support Fragment (android.support.v4.app.Fragment), you need to use a support Loader (android.support.v4.content.Loader).

If you're using native fragments (android.app.Fragment), then you need to use the native Loaders (android.content.Loader).

chessdork
  • 1,999
  • 1
  • 19
  • 20
  • thanks mate @chessdork whats the difference b/w native & support fragments ? – Manish Gupta Sep 02 '16 at 15:55
  • The support library backports functionality to older versions of android. For example, Fragments were introduced in API 11, but a support fragment can be used in API 7. Here's some more discussion on it: http://stackoverflow.com/questions/17295497/fragment-or-support-fragment. – chessdork Sep 02 '16 at 19:46