如何启动Service
开发人员可以使用Intent激活Service组件。
激活Service组件的方式有:
(1)调用Context定义的startService()方法;
(2)调用Context定义的bindService()方法 。
启动Service的开发流程
启动Service的开发流程如下:
1.创建java类,继承android.app.Service;
2在AndroidMainfast.xml中的<application>下添加<service>子节点,配置
创建的Service;
3.在Activity中调用startService(Intent intent)方法启动Service
显示或隐士启动Service
(1)无论是显示Intent或隐身Intent都可以激活Service组件
(2)如果需要实现进程间通信,则应该价为Service组件配置隐式意图过滤器
停止Service
(2)在Service中调用stopSelf()方法可以停止自身。
开发人员可以使用Intent激活Service组件。
激活Service组件的方式有:
(1)调用Context定义的startService()方法;
(2)调用Context定义的bindService()方法 。
启动Service的开发流程
启动Service的开发流程如下:
1.创建java类,继承android.app.Service;
2在AndroidMainfast.xml中的<application>下添加<service>子节点,配置
创建的Service;
3.在Activity中调用startService(Intent intent)方法启动Service
显示或隐士启动Service
(1)无论是显示Intent或隐身Intent都可以激活Service组件
(2)如果需要实现进程间通信,则应该价为Service组件配置隐式意图过滤器
停止Service
停止Service的方法:
(2)在Service中调用stopSelf()方法可以停止自身。