title: Getting application context into fragment, ViewPager
body: <p>I'm writing a simple app with swipe view using <code>viewpager</code> and <code>fullscreen</code> fragments. In one of fragments I want to check internet connection status before displaying some data but I can't get the application context. I've found a lot of topics on this issue, but none of solutions works for me. I am using <code>getApplication()</code> within fragment but even though I get error <code>"Unreacheable statement"</code>.</p>
  
  <p>Any advice?</p>
  
  <pre><code>import android.support.v4.app.FragmentActivity;
  import android.support.v4.view.ViewPager;
  import android.os.Bundle;
  
  public class MainActivity extends FragmentActivity {
  
  ViewPager viewPager;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      //setting fragment view pager
      viewPager = (ViewPager)findViewById(R.id.pager);
      PagerAdapter pagerAdapter = new   PagerAdapter(getSupportFragmentManager());
      viewPager.setAdapter(pagerAdapter);
      }
  }
  </code></pre>
  
  <p>activity_main.xml</p>
  
  <pre><code>&lt;android.support.v4.view.ViewPager
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/pager"
  android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  &lt;/android.support.v4.view.ViewPager&gt;
  </code></pre>
  
  <p>First fragment</p>
  
  <pre><code>import android.support.v4.app.Fragment;
  import android.os.Bundle;
  import android.support.annotation.Nullable;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  public class CurrentWeatherFragment extends Fragment {
  
  //flaga dla statusu polaczenia z internetem
  Boolean isInternetPresent = false;
  
  //klasa detektora połączenia
  ConnectionDetector cd;
  
  
  @Nullable
  @Override
  
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View v = inflater.inflate(R.layout.currentweather, container, false);
      return v;
  
      //tworzenie klasy detektora
      cd = new ConnectionDetector(getActivity().getApplicationContext());
  
      //sprawdzenie czy jest polaczenie z internetem
      isInternetPresent = cd.isConnectingToInternet();
      }
  }
  </code></pre>
  
  <p>Pager Adapter class</p>
  
  <pre><code>import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  
  public class PagerAdapter extends FragmentPagerAdapter {
  
  public PagerAdapter(FragmentManager fm) {
      super(fm);
  }
  
  @Override
  public Fragment getItem(int arg0) {
      switch (arg0){
          case 0:
              return new CurrentWeatherFragment();
          case 1:
              return new ForecastFragment();
          default:
              break;
      }
      return null;
  }
  
  @Override
  public int getCount() {
      return 2;
      }
  }
  </code></pre>