Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling Location Manager twice in a service in android
    primarykey
    data
    text
    <p>I am trying to call location manager twice in my service.</p> <p>First it will call the Manager onStart and then I am putting a timer for 20 seconds and I am calling it again.</p> <p>The first time it is working but the second time after 20 seconds the location manager is not called at all..</p> <p>Below is the code that I have tried:</p> <pre><code> public void onStart(Intent intent, int startId) { super.onStart(intent, startId); Log.e("Location1", "Inside onStart"); t = new Timer(); locationFirst = "First"; talker = new TextToSpeech(this, this); location = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationListener = new MyLocationListener(); location.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 10,locationListener); } public void testMethod() { //Declare the timer //Set the schedule function and rate t.scheduleAtFixedRate(new TimerTask() { @Override public void run() { Log.e("Time",""+time); time += 1; String todis = String.valueOf(time); if(todis.contains("20")) { Looper.myLooper(); Looper.prepare(); talker.speak("Testing Service inside 20 in a App",TextToSpeech.QUEUE_ADD,null); locationFirst = "Second"; locationTocall(); time = 0; t.cancel(); } } }, 0, 1000); } public void locationTocall() { locationListener = new MyLocationListener(); location.requestLocationUpdates(location.NETWORK_PROVIDER, 5000, 10,locationListener); } private class MyLocationListener implements LocationListener { @Override public void onLocationChanged(Location loc) { Log.e("Location1", "Inside MyLocation"); String longitude = String.valueOf(loc.getLongitude()); String latitude = String.valueOf(loc.getLatitude()); String s = latitude+"\n"+longitude; Log.e ("Location1", " "+s); location.removeUpdates(locationListener); if(locationFirst.equalsIgnoreCase("FIRST")) { testMethod(); } else { } } @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload