android - Android App Widgets 是运行在应用进程还是宿主进程?

标签 android process widget android-appwidget

我对默认情况下 App Widget 在哪个进程中运行感到有点困惑。 在 Android Developers,我读到:

"Every application runs in its own process and all components of the application run in that process, by default" - From: http://developer.android.com/guide/components/processes-and-threads.html

我的教科书说:

"Android App Widgets do not run in the application process, but in the host’s process. Therefore, the App Widget uses the RemoteViews class to define its user interface.The RemoteViews class supports a subset of the overall View hierarchy, for display in another process. Generally speaking, you want to configure the RemoteViews object and send it to the App Widget Manager during the onUpdate() method. However, you also need to update it when an instance is created and a configuration activity exists." From: Android Wireless Application Development Volume II 3rd Edition, page 370

之前也有人问过这个问题,答案是“相同的过程”: Does an android widget run in the same process as it's app

谁能帮助我了解 Android 应用程序小部件是在其自己的进程中运行还是与主应用程序运行在同一进程中。谢谢

最佳答案

这取决于您认为“Android App Widget”实际上是什么:

  • 如果您认为应用小部件是在主屏幕上运行的一些 UI,那么该 UI 就是由主屏幕的进程呈现的。

  • 如果您认为应用小部件是 AppWidgetProvider 的子类,那么它会在您自己的应用进程中运行。

应用微件系统是一种插件机制。主屏幕在 Android 框架的协助下,从 AppWidgetProvider 请求 RemoteViews 对象。那些 RemoteViews 表示要由主屏幕呈现的 UI。但是,创建 RemoteViews 的工作将在您的流程中,就像您的任何其他应用程序组件一样。通常,处理点击事件的工作将通过 PendingIntent 路由到您的流程。

关于android - Android App Widgets 是运行在应用进程还是宿主进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24002034/

相关文章:

c# - 使用C#检查运行进程的结果

java - 使用 Java 运行时执行命令

ios - CupertinoSegmentedControl 没有起始值字段。我该如何初始化? ( flutter ;ios)

android - 从 apk 执行 adb shell input swipe 命令

android - 以编程方式通过USB将文件从android传输到计算机

android - WebView 中的 YouTube 移动网站上的视频不起作用 - Android

android - ScrollView 不显示顶部

java - 如何知道用户何时关闭 Java 中使用 exec() 执行的程序

仅限小部件的应用程序 : Default Activity not found

android - 以编程方式更改Android小部件ImageButton的src图像