0

I am trying to use AsyncTaskLoader to load data from a server and then I will put it in a list view later on. I followed this tutorial on YouTube. However, when I try to call the loader from another class which extends fragment, the loader won't accept the context.

I tried:

  1. getActivity()
  2. getActivity().getApllicationContext()

Neither worked.

AstroCB
  • 12,337
  • 20
  • 57
  • 73

1 Answers1

1

You should not be creating a Loader directly, you need to use the LoaderManager and call the initLoader() method. The manager is acquired using your Activity, so it already provides the correct context. If you are using the support library to support pre-3.0 devices, be sure to derive your Activity from FragmentActivity.

Larry Schiefer
  • 15,687
  • 2
  • 27
  • 33