I'd like to check the user's location every 4 hours or so, and I don't want to leave my app running to do this. It looks like using a GcmTaskService with a PeriodicTask will let my service get called (WakefulBroadcastReceiver has restrictions against starting tasks when the app is stopped in Android 6+), and it will be compatible back to Android 4.4 (unlike JobScheduler) - my lowest supported Android version.
The issue is that GcmTaskService's onRunTask method is synchronous, but I want to use that to ask for a location and process the result (LocationManager will call my LocationListener implementation asynchronously).
How should this be handled?
Use a simple wait/notify: