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

309 Views Asked by At

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 ?enter image description here

1

There are 1 best solutions below

1
On

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.