Android Checking connectivity from Thread
<p>I have a service running in the background to get data. I would like to check the connectivity before getting it.</p>

<pre><code>public class DataManager extends Thread {
static final long DELAY = 170000;
Context c;
String stop;

public DataManager(Context argContext) {
    c = argContext;
    stop = "F";
 }

public void StopPlease()
{
    stop = "T";
}  
@Override
public void run() {
       while (true) { 

             try {
                 if (stop=="F")
                 {
                     if(Functions.isOnline(c))
                     {
                         //run the data table loaders for each data type

                         Log.i("MobileViaNetData", "running aircraft data update");
                         DataLoader_Aircraft acloader = new DataLoader_Aircraft(c);
                         acloader.run();
                         Thread.sleep(DELAY);
                     }
                     else
                     {
                         Thread.sleep(DELAY);
                         Toast.makeText(c, "NOT CONNECTED AT THIS TIME", Toast.LENGTH_LONG).show();
                     }
                 }
                 else {
                     break;
                 }
             } catch (InterruptedException e) {
                    e.printStackTrace();
           }
     }
   } 
}

    public class Functions {

    public static boolean isOnline(Context context) 
    {     
        ConnectivityManager cm = (ConnectivityManager)    context.getSystemService(Context.CONNECTIVITY_SERVICE);     
        NetworkInfo netInfo = cm.getActiveNetworkInfo();     
        if (netInfo != null &amp;&amp; netInfo.isConnected()) 
        {         
            return true;     
        }     
            return false; 
    } 
}
</code></pre>

<p>This works great. But for checking( for when no Wi-Fi) if I change it to "if(!Functions.isOnline(c))" it's throwing an error</p>

<pre><code>10-24 13:59:57.970: ERROR/AndroidRuntime(2972): FATAL EXCEPTION: Thread-12
10-24 13:59:57.970: ERROR/AndroidRuntime(2972): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
</code></pre>

<p>IS THIS A CORRECT WAY TO CHECK CONNECTIVITY ? </p>
