1

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!

user2226184
  • 23
  • 1
  • 5

1 Answers1

1

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I know that a continuously-running service is not really nice, but its essential for the application to function. The service only references two FileObservers, so the impact on battery life is very little to none. Do you have an idea how to get the new files my Observers missed while the CPU was in deep sleep? – user2226184 Jun 08 '13 at 11:50
  • @user2226184: "I know that a continuously-running service is not really nice, but its essential for the application to function" -- you are welcome to your opinion. Users, and I, are welcome to ours. "Do you have an idea how to get the new files my Observers missed while the CPU was in deep sleep?" -- what evidence do you have that you are missing anything? If the CPU is stopped, nobody else's processes are running either, and so they cannot be manipulating files. – CommonsWare Jun 08 '13 at 11:56
  • The purpose of the app is to monitor a folder and sync changes. The service can be easily disabled in the app settings. Thats a good point, users reported that the sync is missing files while the device was in standby, I think I have to further investigate this problem. – user2226184 Jun 08 '13 at 12:03