My app runs a FileObserver
inside a service (the service runs 10 minutes after a temp file is created, and it observes the file for 60 seconds in order to delete it if it's not used).
Due to Android 8 restrictions, I cannot start a service from background. AFAIK alternatives are:
- Running a foreground service (but I don't want to show a notification icon)
- Use
JobService
(but it's only available since API 21) - Use
JobIntentService
JobIntentService
runs onHandleWork
on a background thread, and upon returning, the work will be considered complete. So, the question is:
How can I wait until FileObserver
finishes? Is it ok to use something like while(!fileObserverFinished) Thread.sleep(100);
? Is there a better way?