Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Although the documentation is not specific about it, I suggest you perform the call to <code>LocationManager.requestLocationUpdates()</code> in the main (UI) thread. You can use a <a href="http://developer.android.com/reference/android/os/Handler.html" rel="nofollow">Handler</a> to accomplish that if the call originates from a separate thread.</p> <p>BTW, if you want your service to run in a separate thread, I suggest you extend <a href="http://developer.android.com/reference/android/app/IntentService.html" rel="nofollow">IntentService</a> and override the <code>onHandleIntent()</code> method, it is easier that way.</p> <p><strong>Further advice:</strong></p> <p>If you want your <code>Service</code> to run even when the phone is in sleep mode, you need a wake lock.</p> <p>Hint: You don't have to make it run continuosly, that will consume a lot of battery needlessly. Make your <code>Service</code>collect a single location, save it to a local database or deliver it to a bound activity and then stop, and then schedule that <code>Service</code> to run from time to time using <code>AlarmManager</code>.</p> <p>It goes like this: <code>AlarmManager</code> calls a <code>WakefulBroadcastReceiver</code>, which by its turn calls your <code>Service</code>.</p> <p>I suggest you read the <a href="https://developer.android.com/reference/android/support/v4/content/WakefulBroadcastReceiver.html" rel="nofollow">WakefulBroadcastReceiver</a> documentation, it will provide a wake lock for your service automatically (which you have to manually release before the service stops).</p>
    singulars
    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.
    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