سؤال

I have a class that works as a recursive fileobserver. What it does is makes a file observer for all of the directories in a parent directory and then starts watching them. I know it works because when in debug mode, it logs all of the file changes in logcat. But when I disconnect from the debugger and restart the app, it makes the Started and Set Up logs but it doesn't catch any file changes. Is it possible that the garbage collector is cleaning up because the debugger isn't live and watching? I don't think that's true because the Intentservice that runs it never dies.

EDIT: I changed the intentservice to a nonstopintentservice and the same thing is still happening. So the service is not getting destroyed.

What do you think?

Thanks

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

المحلول

It turns out that even though the debugger was listing the intent service as still alive, it really wasn't and the file observers were being finalized. So I wrote a thread to fool the garbage collector into letting the objects exist.

نصائح أخرى

I have tried with service and in another thread. But none worked. I think the problem is FileObserver is garbage collected.

Warning: If a FileObserver is garbage collected, it will stop sending events. To ensure you keep receiving events, you must keep a reference to the FileObserver instance from some other live object

http://developer.android.com/reference/android/os/FileObserver.html

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