gpt4 book ai didi

机器人:启用和服务

转载 作者:可可西里 更新时间:2023-11-01 19:08:58 28 4
gpt4 key购买 nike

我目前正在学习如何在 Android 上创建和使用服务。我查看了 android SDK 以获得进一步的帮助,我发现了 android:enable=[true |假]

在SDK中是这样说的:

The <application> and <service> attributes must both be "true" (as they both are bydefault) for the service to be enabled. If either is "false", the service is disabled;it cannot be instantiated.

所以我想知道什么是兴趣/为什么(一般来说)

  • 将应用程序启用设置为“false”。
  • 将服务启用设置为“false”。

我说,如果我们将服务启用设置为 false,则无法调用该服务,那么我们为什么要首先创建该服务?

谢谢你,抱歉这么长的消息。

最佳答案

setting the application enables as "false".

我不知道这样做有什么好的理由。

I say that if we put service enable as false there is no way to call that service, so why we create that service in the first place?

一般来说,这是对的。 android:enabled 实际上是为所有组件继承的,因此它不是服务所独有的。以下是可能使用它的场景:

  • Activity:您希望在启动器中有第二个图标,但前提是用户通过应用内购买购买东西(例如,升级到“Pro”功能)

  • BroadcastReceiver:您想在启动时通过ACTION_BOOT_COMPLETED 获得控制权,但您并不总是需要它

  • ServiceContentProvider:您有一系列应用,您只需要(并且希望)一个服务/内容提供者的实现,即使用户安装了不止一款来自您家庭的应用

在这些情况下,您可能会在 list 中禁用组件 (android:enabled="false"),并使用 PackageManagersetComponentEnabledSetting() 以便稍后有条件地启用它们。

关于机器人:启用和服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8272173/

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