2

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:

  1. Running a foreground service (but I don't want to show a notification icon)
  2. Use JobService (but it's only available since API 21)
  3. 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?

ColdFire
  • 6,764
  • 6
  • 35
  • 51
Sergio Viudes
  • 2,714
  • 5
  • 26
  • 44

0 Answers0