android:enable and services

后端 未结 2 1647
自闭症患者
自闭症患者 2020-12-24 08:23

I m currently learning how create and use services on android. I looked on the android SDK for further help and i found the android:enable=[true | false]. <

2条回答
  •  Happy的楠姐
    2020-12-24 08:58

    setting the application enables as "false".

    I know of no good reason for doing this.

    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?

    Generally, that is true. android:enabled is, in effect, inherited for all components, so it is not unique to services. Here are scenarios where it might be used:

    • Activity: you want to have a second icon in the launcher, but only if the user purchases something through in-app purchasing (e.g., upgrades to "Pro" features)

    • BroadcastReceiver: you want to get control at boot time via ACTION_BOOT_COMPLETED, but you do not need that all of the time

    • Service and ContentProvider: you have a family of apps, where you only need (and want) one implementation of the service/content provider to be around, even if more than one app from your family are installed by the user

    In these cases, you might have the component disabled (android:enabled="false") in the manifest, and use PackageManager and setComponentEnabledSetting() to conditionally enable them later on.

提交回复
热议问题