FileObserver listening on background, Android O

孤人 提交于 2020-01-24 13:08:11

问题


I have FileObserver in my application, now it runs on the background and if new file registered - instantiate uploading of it to some server in foreground service.

In Android O we should use FirebaseJob Dispatcher to do some job in background, but how could we apply it for FileObserver? Is there any way to analyze data in background? Or maybe it's fail to use FileObserver since now?


回答1:


but how could we apply it for FileObserver?

You can't.

Is there any way to analyze data in background?

That has not changed with Android 8.0 (O). Create a sticky foreground service, then live with the unreliability, as your process still will not run forever. Also, live with the user complaints that your app is running all of the time.

Or maybe it's fail to use File Observer since now?

Using FileObserver has never been reliable, as Android can terminate any process at any time, by user choice (e.g., "Force Stop" in Settings) or to free up system RAM. Using a sticky foreground service is as close as you can get to having an everlasting service/process, and even it will not last forever.

Android 8.0 has not changed any of this.

Depending on your use case, you could try switching to JobScheduler and using it to monitor a MediaStore Uri via addTriggerContentUri().



来源:https://stackoverflow.com/questions/44543572/fileobserver-listening-on-background-android-o

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