gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 14:49:16 35 4
gpt4 key购买 nike

我对默认情况下 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/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com