If i do the following, does it start the service?
PackageManager pm = context.getPackageManager();
pm.setComponentEnabledSetting(
new ComponentName(context, MyService.class),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
If not, what does it do?
http://developer.android.com/reference/android/content/pm/PackageManager.html
i read the javadoc, it just said ‘Set the enabled setting’.
No. Calling
startService()starts the service.Components, like services, can be enabled or disabled. Disabled components cannot be started.
For example, let’s suppose you wanted to respond to some system broadcast, but only some of the time. You could have your
<receiver>element be disabled in the manifest, then enable it using the code you show above when you need it. That way, you only need to have the receiver responding to the broadcast when it is needed, not all of the time.