title: Call AsyncTask in the parent activity from fragment
body: <p>I have an activity with fragment pager and I want to know how to call an asynctask located on that activity from fragment .<br />
  <strong>AddActivity.java</strong></p>
  
  <pre><code>public class AddActivity extends FragmentActivity {
  
      ViewPager vp;
      ProgressDialog dialog;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_add);
  
          vp = (ViewPager) findViewById(R.id.pager);
          PagerAdapter pa = new FragPagerAdapter(getSupportFragmentManager());
          vp.setAdapter(pa);
  
      }
  
  
      //This void to get All field from the differents fragments and put them into jsonObject
      protected JSONObject createJsonObjectVR () {
          ...
      }
  
      // Call the Post Method
      public class addVR extends AsyncTask&lt;String, String, String&gt; {
           ...
      }
  </code></pre>
  
  <p><strong>OtherFragment.java</strong></p>
  
  <pre><code>public class OtherFragment extends Fragment {
      Button btn;
  
      public OtherFragment() {
          // Required empty public constructor
      }
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View view = inflater.inflate(R.layout.fragment_other, container, false);
          btn = (Button) view.findViewById(R.id.send);
          btn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  // Here I want to call the createVR asynctask in the parent Activity
              }
          });
          return view;
      }
  }
  </code></pre>
  
  <p><strong>FragPagerAdapter</strong></p>
  
  <pre><code>public class FragPagerAdapter extends FragmentPagerAdapter {
  
      public FragPagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int index) {
  
          switch (index) {
              case 0:
                  // First Fragment The main
                  return new FirstFragment();
              case 1:
                  // Milk (Second) fragment activity
                  return new SecondFragment();
              case 2:
                  // Housing (Third) fragment activity
                  return new HousingFragment();
              case 3:
                  //Feeding (fourth) fragment activity
                  return new FeedingFragment();
              case 4:
                  // Other (Fith the last) fragment activity
                  return new OtherFragment();
          }
  
          return null;
      }
  
      @Override
      public int getCount() {
          // get item count - equal to number of tabs
          return 5;
      }
  
  }
  </code></pre>