title: Retrieve Context from a fragment
body: <p>I created a class to retrieve comments from a JSON encoding from a PHP file. This class, extends from AsyncTask:</p>
  
  <pre><code>public class RecuperarComentarisFoto extends AsyncTask&lt;String, String, String&gt;{
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          pDialog = new ProgressDialog(????);
          pDialog.setMessage("Creating Product..");
          pDialog.setIndeterminate(false);
          pDialog.setCancelable(true);
          pDialog.show();
      }
  
      @Override
      protected String doInBackground(String... arg0) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      protected void onPostExecute(String result) {
          // TODO Auto-generated method stub
          super.onPostExecute(result);
      }
  
  }
  </code></pre>
  
  <p>As you can see, I'm trying to show a ProgressDialog while the "doInBackground" proccess is working. But progressDialog constructor, asks for a Context, and I don't know how to provide it.</p>
  
  <p>I'm calling this class from a Fragment, so I can't access the context like this:</p>
  
  <pre><code>pDialog = new ProgressDialog(MyFragmentA.context);
  </code></pre>
  
  <p>The "main" acitivity is called: AndroidViewPagerActivity which extends FragmentActivity.</p>
  
  <p>(By main, I mean that it's the one that is creating the tabs, and managing the navigation between them.)</p>
  
  <p>This is it's code:</p>
  
  <pre><code>public class AndroidViewPagerActivity extends FragmentActivity {
  ViewPager mViewPager;
  TabsAdapter mTabsAdapter;
  
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      mViewPager = new ViewPager(this);
      mViewPager.setId(R.id.pager);
      setContentView(mViewPager);
  
      final ActionBar bar = getActionBar();
      bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
      bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_HOME);
      bar.hide();
  
      mTabsAdapter = new TabsAdapter(this, mViewPager);
      mTabsAdapter.addTab(bar.newTab().setText("Fragment A"), MyFragmentA.class, null);
  
      if (savedInstanceState != null) {
          bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
      }
  
  }
  </code></pre>
  
  <p>How can I access the context? Which context should I use? "AndroidViewPagerActivity" context? So how can I access its context from a fragment?</p>
  
  <p>Thank you.</p>
  
  <p>Sergi</p>