一、服务的定义
服务是Android种实现程序后台运行的解决方案
二、创建一个服务

 public class MyService extends Service { //需要重写的函数 onCreate() //创建服务时候调用 onStartCommand()  //启动服务时调用, onDestory()   //服务销毁的时候调用 public IBinder onBind(Intent intent)  用于和其他组件(活动)通信的时候用 }

三、开启和停止一个服务
开启和停止一个服务都是在活动中进行的。通过Intent

Intent start=new Intent(this,MyService.class)startService(start);Intent stop=new Intent(this,MyService.class)stopService(stop);

除了在活动中停止服务之外,在服务的任何地方调用stopSelf()都会停止服务。

更多相关文章

  1. 将图片存储到Sqlite和取出
  2. Android-- Dialog对话框的使用方法
  3. Android开发--玩转WebView
  4. Android提高第四篇之Activity+Intent
  5. hunting job
  6. Android之Widget (微件、小组件)
  7. Android调用第三方百度APP进行导航
  8. android 调用系统命令实现关机
  9. Android(安卓)SharedPreferences 详解 源码解析

随机推荐

  1. 【转】android shape指定那几个边有边框
  2. Android计算器源码
  3. android内置和外置sdcard区别
  4. Android应用程序组件Content Provider在
  5. android 模拟器横竖切换
  6. Android 远程链接 daemon not running 解
  7. android > Android实现计时与倒计时的几
  8. android6.0创建文件问题
  9. Android 进化
  10. Android Jetpack Navigation 的使用