Android——Service
16lz
2021-01-26
一、服务的定义
服务是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()都会停止服务。
更多相关文章
- 将图片存储到Sqlite和取出
- Android-- Dialog对话框的使用方法
- Android开发--玩转WebView
- Android提高第四篇之Activity+Intent
- hunting job
- Android之Widget (微件、小组件)
- Android调用第三方百度APP进行导航
- android 调用系统命令实现关机
- Android(安卓)SharedPreferences 详解 源码解析