Google nearby API background scan doesn´t work after application kill

為{幸葍}努か 提交于 2019-11-30 22:01:27

Haven't really tried using one yet, but have you considered/checked on using a Service? As per the description:

A service can essentially take two forms:

Started

A service is "started" when an application component (such as an activity) starts it by calling startService(). Once started, a service can run in the background indefinitely, even if the component that started it is destroyed. Usually, a started service performs a single operation and does not return a result to the caller. For example, it might download or upload a file over the network. When the operation is done, the service should stop itself.

Bound

A service is "bound" when an application component binds to it by calling bindService(). A bound service offers a client-server interface that allows components to interact with the service, send requests, get results, and even do so across processes with interprocess communication (IPC). A bound service runs only as long as another application component is bound to it. Multiple components can bind to the service at once, but when all of them unbind, the service is destroyed.

You could create a Service that runs the scan continuously until such time that you choose to stop/destroy it. The docs itself already has step on Creating a Started Service. Just read it thoroughly.

Hope this helps somehow. Good luck.

There are two ways to kill an app. If you find the app in Settings > Apps and press "Force Stop", or equivalently if you run adb shell am force-stop <package>, that kills the Nearby subscription too. But if you kill the app by swiping it away in the recents view, or by using adb shell kill <process-id>, the Nearby subscription should stay alive and wake your app with a PendingIntent.

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