In my app, a user will request location updates. When this happens, the main activity starts a Service that will start a location request.
My problem is, if the services is started, say 3 times in a two minute period, then it does not operate properly.
So, basically, I need the service to put the start request on hold until the current start is completely finished.
Each time my service is started, it can take up to ten minutes for it to complete, and the service responds to each start request differently based on the intent data that was passed to it.
I would be happy with (actually prefer) there being one location request for each of the three start requests that happened in the two minute period, but the intent data might be different from each of the three start requests.
So, I tried using IntentService to overcome this and handle all three requests one at a time, but then
LocationManager.requestLocationUpdates(...)
is not called. I understand this is likely due to onHandleIntent(...) pretty much immediately finishing and essentially not giving the location request time to respond. I have a handler that stops the location request after 7 minutes (3 mins for testing), and then location information is passed to other methods that return UI updates to the user. UI updates return, they are just null because the location updates fail.
I'm thinking I could use the onHandleIntent in an IntentService to start my service and pass the intent data to it, but that seems like a really bad practice, and there's probably a better way to do it. EDIT: That definitely won't work because onHandleIntent will immediately start my locationService anyway, so there would be no waiting period.
Also, any Toasts called within onHandleIntent do not show at all, though everything from my onCreate() works like it should.
I'm having a really hard time finding any answer to this, and any help would be greatly appreciated. Here's the gist of my code:
public class myService extends IntentService {
public findMyDroidService() {
super("findMyDroidService");
}
@Override
protected void onHandleIntent(Intent intent){
intent.getExtras();
fromIntentString = intent.getStringExtra("toIntentStringExtra");
Toast.makeText(this, fromIntentString, Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Intent Handled", Toast.LENGTH_SHORT).show();
locMan.requestLocationUpdates(locListener,...);
}
@Override
public void onCreate(){
super.onCreate();
locListener = new LocationListener(){
//code goes here
}
}
}
Also, my location listener is instantiated within the onCreate();