7.2本地服务 ■7.2.1服务管理 o隐式启动则测需要在注册Service时,声明Intent-.-filter 的action属性 <service android:name=".RandomService"> 2 <intent-filter> 3 <action android:name="com.example.RandomService"/> 4 </intent-filter> 5/service
7.2 本地服务 n 7.2.1 服务管理 q 隐式启动则需要在注册Service时,声明Intent-filter 的action属性 1 <service android:name=".RandomService"> 2 <intent-filter> 3 <action android:name=“com.example.RandomService" /> 4 </intent-filter> 5 </service>
7.2本地服务 ■7.2.1服务管理 o在隐式启动Service时,需要设置Intent的action属 性,这样则可以在不声明Service所在类的情况下启 动服务。隐式启动的代码如下 1 final Intent servicelntent=new Intent(); 2 servicelntent.setAction("com.example.RandomService"): 口如果Service和调用服务的组件在同一个应用程序中,可 以使用显式启动或隐式启动,显式启动更加易于使用, 且代码简洁。但如果服务和调用服务的组件在不同的应 用程序中,则只能使用隐式启动
7.2 本地服务 n 7.2.1 服务管理 q 在隐式启动Service时,需要设置Intent的action属 性,这样则可以在不声明Service所在类的情况下启 动服务。隐式启动的代码如下 1 final Intent serviceIntent = new Intent(); 2 serviceIntent.setAction("com.example.RandomService"); q 如果Service和调用服务的组件在同一个应用程序中,可 以使用显式启动或隐式启动,显式启动更加易于使用, 且代码简洁。但如果服务和调用服务的组件在不同的应 用程序中,则只能使用隐式启动