zoukankan      html  css  js  c++  java
  • Android开发ABC之:Service

    下面是SDK doc对Service的描述:

    A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use. Each service class must have a corresponding <service> declaration in its package's AndroidManifest.xml. Services can be started with Context.startService() and Context.bindService().

    几个要点:

    Service是应用的一个组件,当应用想要执行长时间的任务,并且不跟用户交互或者为其他应用提供功能时使用。Service并不代表一个新的进程或者线程,而是在宿主进程的主线程中运行,所以它并不适合Computing intensive的任务,比如播放MP3或者视频编解码等,需要创建新线程来完成。

    每个service类都必须在AndroidManifest.xml中声明,否则,会报告“Unable to start service Intent U=0: not found”错误。

    Service不能自己启动,只能使用Context.startService() 和 Context.bindService()启动。

    下面是来自SDK doc:

    • A facility for the application to tell the system about something it wants to be doing in the background (even when the user is not directly interacting with the application). This corresponds to calls to Context.startService(), which ask the system to schedule work for the service, to be run until the service or someone else explicitly stop it.
    • A facility for an application to expose some of its functionality to other applications. This corresponds to calls to Context.bindService(), which allows a long-standing connection to be made to the service in order to interact with it.
  • 相关阅读:
    第二章 算法基础 思考题2-4(逆序对)
    JSF中使用f:ajax标签无刷新页面改变数据
    JSF在ui:include中传递参数到对应控制层
    JSF通过超链接传递参数到控制层
    给JavaScript文件传入参数的几种方法
    Spring 与 @Resource注解
    GWT嵌入纯HTML页面
    一个分类,两个问题之ArrayList
    GWT更改元素样式属性
    Hello 2019 D 素因子贡献法计算期望 + 概率dp + 滚动数组
  • 原文地址:https://www.cnblogs.com/whyandinside/p/2904775.html
Copyright © 2011-2022 走看看