服务器xml代码
<service android:name=".BookManagerService"
android:process=".remote"
android:enabled="true"
android:exported="true"/>
android:enabled
这个属性用于指示该服务是否能够被实例化。如果设置为true,则能够被实例化,否则不能被实例化。默认值是true。
元素有它自己的enabled属性,它的这个属性适用于应用中所有的组件,包括service组件。对于被启用的服务,和元素的enabled属性都必须是true(默认值都是true)。如果有一个元素的enabled属性被设置为false,该服务就会被禁用,而不能被实例化。
客户端如何调用
intent.setComponent(new ComponentName("com.example.administrator.myapplication",
"com.example.administrator.myapplication.BookManagerService"));
boolean cc=bindService(intent,mConnection, Context.BIND_AUTO_CREATE);