title: how to get location in android debugging mode?
body: <p>I am trying to get gps and network location in android. But every time I get location null.
  <code>LocationManager</code> getting null in debugging mode. </p>
  
  <p>Here is my Code</p>
  
  <pre><code>public class LocationService extends Service {
  
  private static Timer timer = new Timer();
  public Location mLocation;
  
  @Override
  public void onCreate() {
      super.onCreate();
      _startService();
  }
  
  @Nullable
  @Override
  public IBinder onBind(Intent intent) {
      return null;
  }
  
  private void _startService() {
      timer.scheduleAtFixedRate(new TimerTask() {
          @Override
          public void run() {
  
              _serviceWork();
  
          }
      }, 1000, 30000);
  }
  
  private void _serviceWork() {
      new LocationListener() {
          @Override
          public void onLocationChanged(Location location) {
              mLocation.set(location);
          }
  
          @Override
          public void onStatusChanged(String s, int i, Bundle bundle) {
  
          }
  
          @Override
          public void onProviderEnabled(String s) {
  
          }
  
          @Override
          public void onProviderDisabled(String s) {
  
          }
      };
  }
  
  @Override
  public void onDestroy() {
      super.onDestroy();
  
      _shutdownService();
  }
  
  private void _shutdownService() {
      if (timer != null) {
          timer.cancel();
      }
  }
  }
  </code></pre>