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.
  • 相关阅读:
    BootStrap练习
    表单控件练习
    K近邻算法原理
    CSS 边框和颜色
    SVG平移和旋转
    SVG进阶练习
    SVG路标(marker)
    SVG 曲线与文字
    python函数与异常处理
    if-elif-else分支判断语句(附加continue和break)---举例说明
  • 原文地址:https://www.cnblogs.com/whyandinside/p/2904775.html
Copyright © 2011-2022 走看看