title: How to Handle Internet Connection when Requesting Data to RestAPI Android
body: <p>I have <code>asynctask</code> for requesting JSON file from RestAPI, the problem is before webservice send JSON data, my connection have been lost, and get error because of that. I already have <code>ConnectivityManager</code> to check if connection establish i can run the <code>asynctask</code> for requesting JSON. How to handle when <code>asynctask</code> is already running?</p>
  
  <p>This is my <code>ConnectivityManager</code> function:</p>
  
  <pre><code>public bool isOnline()
          {
              ConnectivityManager cm = (ConnectivityManager)GetSystemService(ConnectivityService);
              NetworkInfo activeConnection = cm.ActiveNetworkInfo;
              return activeConnection != null &amp;&amp; activeConnection.IsConnected;
  
          }
  </code></pre>
  
  <p>I'm using Visual Studio 2015 and Xamarin to build Android App.</p>
  
  <p>Thanks in advance</p>