title: Using LoaderCallbacks without Fragment
body: <p>I am doing some hands-on reading on AsyncTaskLoader so I can use the technique to load the contact list. The only time the code works is when I implement the callbacks from a class that extends <code>Fragment</code> as in <code>MyLoader extends Fragment implements LoaderCallbacks&lt;ArrayList&lt;Contact&gt;&gt;</code>. Is there another way? All I really need is the contact list (name, phone, thumbnail), to send to my backend.  When, for example, I try to use <code>Context</code>, since I can get that from any activity by simply doing <code>(Context)this</code>, the code fails to even compile. By context I mean</p>
  
  <pre><code>context.getLoaderManager().initLoader(1, null, this);
  //I already changed to Fragment so don't really remember the exact ".context" line.
  //But someone who has done this will understand the snippet.
  </code></pre>
  
  <p>BTW: I am using multiple references. One is <a href="http://developer.android.com/reference/android/content/AsyncTaskLoader.html">http://developer.android.com/reference/android/content/AsyncTaskLoader.html</a>.</p>
  
  <p>QUESTION (again): Can I use AsyncTaskLoader without Fragment or FragmentActivity?</p>
  
  <p>THE CODE THAT WORKS WITH THE FRAGMENT:</p>
  
  <pre><code>package com.example.contactpreload.utils;
  
  import java.util.ArrayList;
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.LoaderManager.LoaderCallbacks;
  import android.support.v4.content.Loader;
  
  public class LoadingContacts extends Fragment implements LoaderCallbacks&lt;ArrayList&lt;Contact&gt;&gt; {
      ArrayList&lt;Contact&gt; loadedContacts;
      static Fragment fragmentActivity;
  
      public static LoadingContacts newInstance(int arg) {
  
          LoadingContacts f = new LoadingContacts();
          Bundle bundle = new Bundle();
          bundle.putInt("index", arg);
          f.setArguments(bundle);
          fragmentActivity = new Fragment();
          return f;
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          System.out.println("onCreate()");
          int mIndex = getArguments().getInt("index");
          System.out.println(mIndex);
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
  
          System.out.println("onActivityCreated()");
          getLoaderManager().initLoader(1, null, this);
      }
  
      @Override
      public Loader&lt;ArrayList&lt;Contact&gt;&gt; onCreateLoader(int arg0, Bundle arg1) {
  
          System.out.println("onCreateLoader()");
          return new ContactsLoader(getActivity());
      }
  
      @Override
      public void onLoadFinished(Loader&lt;ArrayList&lt;Contact&gt;&gt; loader, ArrayList&lt;Contact&gt; data) {
          loadedContacts = data;
          System.out.println("AND THE CONTACTS ARE: ");
          for (Contact c : loadedContacts) {
              System.out.println("NAME: " + c.getName());
              System.out.println("getPhoneNumberHome: " + c.getPhoneNumber());
          }
  
      }
  
      @Override
      public void onLoaderReset(Loader&lt;ArrayList&lt;Contact&gt;&gt; arg0) {
          System.out.println("onLoaderReset()");
          // TODO Auto-generated method stub
  
      }
  
  }
  
  
  
  package com.example.contactpreload;
  
  import android.os.Bundle;
  import android.support.v4.app.FragmentActivity;
  import android.view.Menu;
  
  import com.example.contactpreload.utils.LoadingContacts;
  
  public class MainActivity extends FragmentActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          LoadingContacts fragment = LoadingContacts.newInstance(1);
          fragment.setRetainInstance(true);
          getSupportFragmentManager().beginTransaction()
              .add(android.R.id.content, fragment).commit();
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
  }
  </code></pre>
  
  <p>MANIFEST:</p>
  
  <pre><code>&lt;uses-sdk
      android:minSdkVersion="8"
      android:targetSdkVersion="16" /&gt;
  </code></pre>