问题
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