Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android:enable and services

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].

in the SDK is said that:

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

So i would like to know what is the interest of/ why (in general)

  • setting the application enables as "false".
  • setting the service enable 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?

Thank you and sorry for such long message.

like image 408
Blood-HaZaRd Avatar asked Nov 25 '11 17:11

Blood-HaZaRd


People also ask

What is Android enabled?

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)

What is process and service in Android?

remember, android is linux: process = any running program. e.g. something with a PID. service = roughly equivalent to a daemon. something running in the background with no direct user interface.

What is the role of services in Android?

Services in Android are a special component that facilitates an application to run in the background in order to perform long-running operation tasks. The prime aim of a service is to ensure that the application remains active in the background so that the user can operate multiple applications at the same time.


2 Answers

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.

like image 157
CommonsWare Avatar answered Oct 21 '22 16:10

CommonsWare


New SAF(Storage Access Framework) is a good example of use of android:enabled attribute. http://developer.android.com/guide/topics/providers/document-provider.html

The android:enabled attribute set to a boolean value defined in a resource file. The purpose of this attribute is to disable the provider on devices running Android 4.3 or lower. For example,

android:enabled="@bool/atLeastKitKat" 

In addition to including this attribute in the manifest, you need to do the following: In your bool.xml resources file under res/values/, add this line:

<bool name="atLeastKitKat">false</bool> 

In your bool.xml resources file under res/values-v19/, add this line:

<bool name="atLeastKitKat">true</bool>
like image 32
Vivart Avatar answered Oct 21 '22 15:10

Vivart