سؤال

i've got a problem with my Android FileObserver.

I have a background service running (returns START_STICKY), which references two FileObservers. Everything is working fine until the device is set to sleep mode, which will stop the service, as far as i know.

  1. Does anybody know what exactly happens to the Service/FileObserver when a device is put to sleep mode?

  2. Can the service get notified before freezing so I can save a file list of the observed folder and compare it to a new list when the device gets waked up again?

I don't want to use a wakelock because of its impact on battery life.

  1. Will the FileObserver Event be fired for changes to folders which happend while my service was set to sleep, as soon as I turn the screen back on?

That can't really test it because usb debugging keeps the device awake.

Thanks for your help!

هل كانت مفيدة؟

المحلول

Everything is working fine until the device is set to sleep mode, which will stop the service, as far as i know

No, it stops the CPU.

Does anybody know what exactly happens to the Service/FileObserver when a device is put to sleep mode?

The CPU is stopped. Stopped CPUs will not execute instructions. It is reminiscent of putting your development computer in suspend mode.

(the details are significantly more complicated but usually are not relevant at the SDK level, IMHO)

Can the service get notified before freezing so I can save a file list of the observed folder and compare it to a new list when the device gets waked up again?

No.

Will the FileObserver Event be fired for changes to folders which happend while my service was set to sleep, as soon as I turn the screen back on?

I haven't tried that.

That can't really test it because usb debugging keeps the device awake.

Then unplug the USB cable. Use Log statements to record the results that you wish to monitor. Plug in the USB cable after your test period to examine LogCat and see your logs.

Generally speaking, your overall solution (continuously-running service) is user-hostile. Please don't complain when users attack you with task killers and the Force Stop button.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top