Android Things,如何捕获进程终止

标签 android hardware android-things pwm android-hardware

由于 Android Things 一次只能运行一个应用程序,因此我不确定在终止/后台运行/恢复进程方面规则与普通 Android 操作系统有何不同。

我的 Android Things 用例并不简单。我正在使用 PWM channel 控制执行器。问题是,如果我设置了“移动命令”,然后出现致命异常或其他此类中断,我的应用程序就会崩溃,但执行器臂会继续移动(因为 PWM 屏蔽保持其功率和值)!由于这些 ARM 控制着一艘移动的船,这是非常危险的。

是否有某种方式,以某种方式拦截进程的终止,以便我可以获得我的 PWM“清零”命令?或者有什么办法可以让 Android Things 在我的主应用死机后立即启动其他进程来执行此操作?

最佳答案

Since Android Things only runs one app at a time, I'm not sure how the rules differ from normal Android OS when it comes to killing/backgrounding/resuming a process.

这不是真的。 Android Things 与 Android 移动设备在多个前台和后台应用程序方面具有相同的语义。但是,由于没有默认的应用程序启动器,您必须 define an application捕获默认的 HOME Intent 并成为前台应用程序。从此应用程序中,您可以根据需要在后台自由启动其他应用程序。

Is there someway, somehow to intercept the killing of the process so I can get my PWM "zero out" commands in? Or is there someway to game Android Things to immediately boot some other process that does this after my main app dies?

Android 会在该应用程序崩溃时自动重启 HOME Activity (除非您已在其之上启动了其他 Activity ,除非您有 UI,否则不一定推荐这样做)。您可以使用它来将您的硬件初始化为默认状态。

另一种选择是让您的电机驱动程序逻辑在后台应用程序的绑定(bind)服务中运行。这将允许主应用程序作为主管运行(当绑定(bind)服务终止时它会收到通知)并重置 PWM(或重新启动服务,从而正确初始化 PWM)。

关于Android Things,如何捕获进程终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55225534/

相关文章:

android - 是否可以在Android手机中获取NFC芯片的型号名称?

Android:以编程方式检测设备是否有硬件菜单按钮

java - 将方法移至单独的类

c# - 如何使用 C# 读取和写入硬件寄存器?

android - Gradle 'XXX' 项目刷新失败

android - 如何创建 Android Things 的 bundle 并将其推送到 OTA 上?

安卓的东西 :Use Speech to text in Raspberry Pi 3 using android things

Android Things OTA 流程

android - 线性布局中的自动调整项目

Android AlertDialog.Builder 对齐文本