启动Service

如何启动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

停止Service的方法:


(1)通过调用Context的stopService(Intent intent)方法可以停止Service,并销毁Service组件2
(2)在Service中调用stopSelf()方法可以停止自身。





你可能感兴趣的:(android)