FileObserver instance is being garbage collected

孤街浪徒 提交于 2019-11-29 05:13:00

I'm guessing the startWatching() method returns immediately, your Thread finishes running, and your method returns. At this point, your FileObserver, being a local variable, is not visible from anywhere. Your thread has finished running and there is no reference to it. Both are garbage collected. Define the FileObserver as a static variable or a field in something that isn't garbage collected, not as a local variable in a method.

Keep fo in the application scope by making it a global variable of your main/UI Activity.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!