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.
  • 相关阅读:
    服务端跳转和客户端跳转的区别
    jsp:include标签与include指令的区别
    jsp错误页不跳转显示500
    使用Cookie进行会话管理
    深入理解重定向和转发
    appium环境搭建(二)----搭建android开发环境
    appium环境搭建(一)----安装appium
    Fiddler实现移动端手机抓包
    黑盒测试人员必备技能
    SVN服务器搭建
  • 原文地址:https://www.cnblogs.com/whyandinside/p/2904775.html
Copyright © 2011-2022 走看看