博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android service 小研究
阅读量:4308 次
发布时间:2019-06-06

本文共 914 字,大约阅读时间需要 3 分钟。

      最近同学搞起了Android开发,自己也捡起来这个玩意来看看。这里先研究一下service

      Service是安卓系统提供的四种组件之一,功能与activity类似,只不过没有activity 的使用频率高。顾名思义Service就是运行在后台的一种服务程序一般很少与用户交互,没有可视化界面。

      定义一个service非常简单,只要继承就可以了,实现其中的那些方法就可以了。service必须在AndroidManifest.xml配置文件中定义

<service   android:name=”myservice”>

<intent-filter>

<action android:name=”com.houyewei.action.MY_SERVICE”/>

</intent-filter>

</service>

intent-filter制定如何访问该service

onBind(Intent intent):是必须实现的一个方法返回接口

onCreate():当service第一次被创建有系统调用

onStart(Intent intent ,int startid):当通过startservice()方法启动service是该方法被调用

 

onDestory():当service不再使用,系统调用该方法

 

创建一个service代码

 

public classs Myservice extends Service

{

   public IBinder onBind(Intent intent)

{

    return null;

}

  public void onCreate()

    {

      super.onCreate();

    }

  public void onStart(Intent intent ,int startId)

   {

     super.onStart(intent,startId);

   }

   public void onDestory()

   {

      super.onDestory();

   

   }

}

转载于:https://www.cnblogs.com/houyewei/archive/2011/12/03/2274915.html

你可能感兴趣的文章
CocoaPods安装和使用教程
查看>>
Beginning Auto Layout Tutorial
查看>>
block使用小结、在arc中使用block、如何防止循环引用
查看>>
iPhone开发学习笔记002——Xib设计UITableViewCell然后动态加载
查看>>
iOS开发中遇到的问题整理 (一)
查看>>
Swift code into Object-C 出现 ***-swift have not found this file 的问题
查看>>
为什么你的App介绍写得像一坨翔?
查看>>
RTImageAssets插件--@3x可自动生成@2x图片
查看>>
iOS开发的一些奇巧淫技
查看>>
常浏览的博客和网站
查看>>
Xcode 工程文件打开不出来, cannot be opened because the project file cannot be parsed.
查看>>
iOS在Xcode6中怎么创建OC category文件
查看>>
5、JavaWeb学习之基础篇—标签(自定义&JSTL)
查看>>
8、JavaWEB学习之基础篇—文件上传&下载
查看>>
reRender属性的使用
查看>>
href="javascript:void(0)"
查看>>
h:panelGrid、h:panelGroup标签学习
查看>>
f:facet标签 的用法
查看>>
<h:panelgroup>相当于span元素
查看>>
java中append()的方法
查看>>