带有bindservice和kotlin的Android Things-onResume和onPause或Coroutines或RxJava [英] Android Things with bindservice and kotlin - onResume and onPause Or Coroutines Or RxJava

查看:250
本文介绍了带有bindservice和kotlin的Android Things-onResume和onPause或Coroutines或RxJava的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此项目中: https://github.com/neuberfran/SmartDrive5 ,文件: ModoComFirebase.kt 我遇到的问题是PID已在使用BCM18,因为此gpio已在 DriverService.kt 中打开归档之前.

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.

我的问题是:Application类 ModoAutomatico.kt 没有onPause和onResume方法.在这种情况下如何使用前台服务解决我的问题?

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 ?

推荐答案

应用程序类ModoAutomatico.kt没有onPause和onResume方法.

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

这是因为Application类是单例.它会在您的应用启动后立即启动,并且永远不会暂停,停止或销毁.由于您已绑定了应用程序中的DriverService,这意味着您的服务也始终在后台运行(除非崩溃).

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已被PID使用,因为此gpio之前已在DriverService.kt文件中打开.

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

一次只能与外围资源建立一个活动连接.如果要使用已经在另一个组件中打开的GPIO,则必须先close()活动的GPIO连接,然后才能打开新的GPIO.

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.

如果您要从服务中管理所有按钮连接,则应用程序的其余部分应与该服务进行对话以与那些外设交互,而不是尝试处理多个GPIO连接.

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.

这篇关于带有bindservice和kotlin的Android Things-onResume和onPause或Coroutines或RxJava的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆