Android应用开发基础Android应用开发基础 (19).pdf
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《Android应用开发基础Android应用开发基础 (19).pdf》由会员分享,可在线阅读,更多相关《Android应用开发基础Android应用开发基础 (19).pdf(15页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、 6.3 自定义服务 本章内容本章内容 第第1节节 Android服务概述服务概述 第第2节节 系统服务系统服务 第第3节节 自定义服务自定义服务 第第4节节 多线程多线程 6.3 自定义服务自定义服务 知识点预览知识点预览#知识点知识点 重点重点 难点难点 应用应用 说明说明 1 启动服务的生命周期 理解服务的生命周期与启动工作原理。2 启动服务的回调函数 理解启动服务时,服务回调方法的执行次序。3 向服务传递数据 理解Intent的设计目并能将数据传至服务。4 服务应答 理解服务的三种应答启动方的方式。5 服务与线程 理解服务存在的目的以及与线程的差异性。6 前台服务 理解前台服务的作用并
2、能熟练应用。6.3 6.3 自定义服务自定义服务 1 Android 自定义服务自定义服务:由研发人员根据不同的需要自行开发的服务。这些服务往往与活动组件等其他组件保存在同一个应用程序中。2 服务生命周期服务生命周期 startService第一次启动服务。onCreate方法执行,但是只会执行一次。随后执行onStartCommand。当startService再次执行。onCreate方法不再执行。onStartCommand反复执行。stopService方法停止服务。服务的onDestory方法将会被执行。6.3 6.3 自定义服务自定义服务 3 Service实现实现 新建一个继承于
3、Service的类,依次下列实现方法 6.3 6.3 自定义服务自定义服务 public class public class MyService2 extends extends Service public void public void onCreate()supersuper.onCreate();Log.d(MyServiceMyService,onCreate executedonCreate executed);public int public int onStartCommand(Intent intent,int int flags,int int startId)Log
4、.d(MyServiceMyService,onStartCommand executedonStartCommand executed);return superreturn super.onStartCommand(intent,flags,startId);public void public void onDestroy()supersuper.onDestroy();Log.d(MyServiceMyService,onDestroy executedonDestroy executed);public public IBinder onBind(Intent intent)Log.
5、d(MyServiceMyService,onBind executedonBind executed);return nullreturn null;3 Service实现实现 开启服务 6.3 6.3 自定义服务自定义服务 Intent startIntent=new new Intent(thisthis,MyService.classclass);startService(startIntent);/启动服务 Intent stopIntent=new new Intent(thisthis,MyService.classclass);stopService(stopIntent);/
6、停止服务 关闭服务 XML配置信息文件 3 Service实现实现 实现效果 6.3 6.3 自定义服务自定义服务 4 服务服务绑定绑定 bindService的生命周期为:onCreate-onBind(只一次,不可多次绑定)-onUnbind-onDestory。onBind()将返回给将返回给 客户端一个客户端一个IBind接口实例,接口实例,IBind允许客户端回调服务允许客户端回调服务的方法的方法 6.3 6.3 自定义服务自定义服务 4 Activity绑定Service 6.3 6.3 自定义服务自定义服务 4 Acitivity与与Service的通信的通信 新建一个继承于Bi
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Android应用开发基础Android应用开发基础 19 Android 应用 开发 基础 19
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内