Open HanteIsHante opened 7 years ago
android:exported="true"
可被其他重程序 调用,不设置默认此项为 false
android:enabled
系统默认启动
true:Service 将会默认被系统启动;不设置则默认为false
android:permission
申明此Service的权限 有提供了该权限的应用才能控制或连接此服务
android:label
显示给用户的服务名称。如果没有进行服务名称的设置,默认显示服务的类名。
<intent-filter>
<action android:name="com.***.****.IRemoteService" />
</intent-filter>
bindService 注意
Intent intent = new Intent(IRemoteService.class.getName());
和上面的Service申明的Action一致
this.bindService(intent, mServiceConnection, Service.BIND_AUTO_CREATE);
BIND_AUTO_CREATE这个Flag从名字就能看出,表示如果Bind的时候,如果还没有Service的实例,就自动创建。
这里有一个地方需要注意,在Android 5.0以后,就不允许使用非特定的Intent来绑定Service了,需要使用如下方法:
Intent intent = new Intent(IRemoteService.class.getName());
intent.setClassName("com.race604.remoteservice", "com.race604.remoteservice.RemoteService");
// 或者setPackage()
// intent.setPackage("com.race604.remoteservice");
bindService(intent, mServiceConnection, BIND_AUTO_CREATE);
android:process=":remote",代表在应用程序里,当需要该service时,会自动创建新的进程。而如果是android:process="remote",没有“:”分号的,则创建全局进程,不同的应用程序共享该进程。
表示该服务是否在另一个进程中运行(远程服务) 不设置默认为本地服务;remote则设置成远程服务