Android Things with bindservice and kotlin - onResume and onPause Or Coroutines Or RxJava

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 17:19:25

问题


In this project: https://github.com/neuberfran/SmartDrive5, file: ModoComFirebase.kt I have issue BCM18 is already in use by PID, Because this gpio was opened in DriverService.kt file before.

My question is: The Application class ModoAutomatico.kt has no methods onPause and onResume. How to use foreground service in this case to solve my Issue ?


回答1:


The Application class ModoAutomatico.kt has no methods onPause and onResume.

This is because the Application class is a singleton. It starts once your app is launched and is never paused, stopped, or destroyed. Since you've bound DriverService from the application, this means your service is also always running in the background (unless it were to crash).

BCM18 is already in use by PID, Because this gpio was opened in DriverService.kt file before.

You can only have one active connection to a peripheral resource at a time. If you want to use a GPIO that is already open in another component, you have to close() the active GPIO connection first before you can open a new one.

If you're going to manage all your button connections from within a service, then the rest of the app should be talking to that service to interact with those peripherals instead of trying to juggle multiple GPIO connections.



来源:https://stackoverflow.com/questions/55410809/android-things-with-bindservice-and-kotlin-onresume-and-onpause-or-coroutines

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