Reputation:
I have a location service. Time to time when the service receive new location i send all the past locations accumulated to the server. I don't really know how wake lock work under android, so do i need to keep a wake lock (or any think else?) when i send the data to the server (I send it in background thread if it's matter)
this is the code of my service if it's matter.
public class mLocationService extends Service implements ALLocationServicesListener {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if ((intent != null) && (intent.hasExtra("Alarm"))) { synchLocations(); }
else {
return Service.START_STICKY;
}
}
private class doSynchLocationsTask extends AsyncTask<JSONObject, Void, Boolean> {
@Override
protected Boolean doInBackground(JSONObject... params) {
//send the data in http
return true;
}
@Override
protected void onPostExecute(Boolean result) {
}
}
private void doSynchLocations(){
new doSynchLocationsTask().execute(null);
}
}
Upvotes: 2
Views: 454
Reputation: 320
If you are using WakefulBroadcastReceiver just call:
boolean completeWakefulIntent (Intent intent)
You can also use android-job library for job scheduling. This way you don't have to worry about wake locks.
Upvotes: 3