title: Android Fatal Timer-0 RunTimeException
body: <p>In Android, i am using Timer class to check wifi connection in mobile every second, because i want to Turn On GPS, when device is not using wifi. But it is showing me fatal Timer-0 RunTimeException.</p>
  
  <p>Here is my timer function</p>
  
  <pre><code>public void checkWifi()
  {
      Timer timer = new Timer();
      TimerTask hourlyTask = new TimerTask() {
          @Override
          public void run()
          {
              boolean isWifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
                               .isConnectedOrConnecting();
              if (!isWifi) {
                  locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
              }
          }
      };
      timer.schedule(hourlyTask, 0l, 1000);
  }
  </code></pre>
  
  <p>Here is my LogCat</p>
  
  <pre><code>  02-14 02:52:53.126: E/AndroidRuntime(1539): FATAL EXCEPTION: Timer-0
    02-14 02:52:53.126: E/AndroidRuntime(1539): Process: com.example.gpsco11wifialert, PID: 1539
    02-14 02:52:53.126: E/AndroidRuntime(1539): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
    02-14 02:52:53.126: E/AndroidRuntime(1539):   at android.os.Handler.&lt;init&gt;(Handler.java:200)
    02-14 02:52:53.126: E/AndroidRuntime(1539):   at android.os.Handler.&lt;init&gt;(Handler.java:114)
    02-14 02:52:53.126: E/AndroidRuntime(1539):   at android.location.LocationManager$ListenerTransport$1.&lt;init&gt;(LocationManager.java:221)
    02-14 02:52:53.126: E/AndroidRuntime(1539):   at android.location.LocationManager$ListenerTransport.&lt;init&gt;(LocationManager.java:221)
    02-14 02:52:53.126: E/AndroidRuntime(1539):   at android.location.LocationManager.wrapListener(LocationManager.java:844)
    02-14 02:52:53.126: E/AndroidRuntime(1539):   at android.location.LocationManager.requestLocationUpdates(LocationManager.java:857)
    02-14 02:52:53.126: E/AndroidRuntime(1539):   at android.location.LocationManager.requestLocationUpdates(LocationManager.java:454)
    02-14 02:52:53.126: E/AndroidRuntime(1539):   at com.example.gpsco11wifialert.GpsC011Wifi$MyLocationListener$4.run(GpsC011Wifi.java:213)
    02-14 02:52:53.126: E/AndroidRuntime(1539):   at java.util.Timer$TimerImpl.run(Timer.java:284)
  </code></pre>