`
modabobo
  • 浏览: 508511 次
文章分类
社区版块
存档分类
最新评论

安卓开发-Application && service

 
阅读更多

Application

Base class for those who need to maintain global application state. You can provide your own implementation by specifying its name in your AndroidManifest.xml's <application> tag, which will cause that class to be instantiated for you when the process for your application/package is created.

There is normally no need to subclass Application. In most situation, static singletons can provide the same functionality in a more modular way. If your singleton needs a global context (for example to register broadcast receivers), the function to retrieve it can be given a android.content.Context which internally usesContext.getApplicationContext() when first constructing the singleton.

------------------------------

上面是Application的doc解释。在application中,oncreate函数中有说明,在这个函数中不要做太多的工作,因为这个oncreate函数的性能直接决定了我们的app启动第一个activity、service或者receiver的速度。doc如下:

Called when the application is starting, before any activity, service, or receiver objects (excluding content providers) have been created. Implementations should be as quick as possible (for example using lazy initialization of state) since the time spent in this function directly impacts the performance of starting the first activity, service, or receiver in a process. If you override this method, be sure to call super.onCreate().

------------------------------

Service

Note that services, like other application objects, run in the main thread of their hosting process. This means that, if your service is going to do any CPU intensive (such as MP3 playback) or blocking (such as networking) operations, it should spawn its own thread in which to do that work. More information on this can be found in Processes and Threads. The IntentService class is available as a standard implementation of Service that has its own thread where it schedules its work to be done.

根据上面的doc来看,service也是运行在主线程中的,所以任何要求长时间的操作,都要放到其他线程中来做。


分享到:
评论

相关推荐

    Android-Service-and-Broadcast-example-application:Android 服务和广播示例应用程序

    Android-Service-and-Broadcast-example-application Android 服务和广播示例应用程序

    android-application-plug-ins-frame-work:从 code.google.compandroid-application-plug-ins-frame-work 自动导出

    安卓应用程序插件化开发框架 -AAP Framework 介绍 这个框架的初衷,是为了方便让程序模块化、插件化,将一个apk应用拆分为多个apk。 不明白这个插件化、模块化是怎么回事的话,可以看看腾讯微信的安卓客户端中的插件...

    安卓开发观察者模式应用-一个service通知多个activity更新ui的实现

    安卓开发观察者模式应用-一个service通知多个activity更新ui的实现, service与activity的交互: 1.接口回调 2.自定义广播 3.观察者模式

    新版Android开发教程.rar

    Android Android Android Android 开发背景 � 计算技术、无线接入技术的发展,使嵌入式系统逐渐有能力对桌面系统常规业务进行支持。 � 谷歌长期以来奉行的移动发展战略:通过与全球各地的手机制造商和移动运营商...

    android-application-background-video-service:[已弃用]关于Android应用程序如何能够使用后置摄像头录制视频而无需用户通知的概念证明

    后台视频服务 这是有关应用程序如何能够使用后置摄像头录制视频而无需用户通知的概念证明。 执行录制需要以下权限: android.permission.CAMERA... 要编译Background Video Service,只需将该项目导入Android Studio或

    Android核心分析(pdf)

    androi的核心分析,android平台开发不可缺少的资料。本书为网上资料转换为pdf文件,内容清单如下: Android核心分析(01)----讨之设计意图 Android核心分析(02)----方法论探讨之概念空间篇 Android核心分析(03)...

    Android高级编程--源代码

    因为没有了人为制造的障碍,所以Android开发人员可以自由地编写能够充分利用日益强大的手机硬件的应用程序。因此,对Android感兴趣的开发人员都把Google在2008年发布Android这一举措作为移动技术发展史上的一个非常...

    android开发入门与实战(下)

    第2章 工欲善其事 必先利其器——搭建Android开发环境 2.1 开发Android应用前的准备 2.1.1 Android开发系统要求 2.1.2 Android软件开发包 2.1.3 其他注意事项 2.2 Windows开发环境搭建 2.2.1 JDK、Eclipse、Android...

    Android课程设计---基于Android系统的音乐播放器设计与实现.doc

    课程名称: 操作系统原理 题 目: 基于Android系统的音乐播放器设计与实现 2012 年 7 月 5 日 课程设计任务书 设计题目:基于Android 系统的音乐播放器设计与实现 初始条件: Linux操作系统,Android开发环境,...

    《Google Android开发入门与实战》.pdf

     本书内容上涵盖了用android开发的大部分场景,从android基础介绍、环境搭建、sdk介绍、market使用,到应用剖析、组件介绍、实例演示等方面。从技术实现上,讲解了5个android平台下的完整综合实例及源代码分析,...

    android开发入门与实战(上)

    第2章 工欲善其事 必先利其器——搭建Android开发环境 2.1 开发Android应用前的准备 2.1.1 Android开发系统要求 2.1.2 Android软件开发包 2.1.3 其他注意事项 2.2 Windows开发环境搭建 2.2.1 JDK、Eclipse、Android...

    Android项目设计与开发:服务的概念.ppt

    嵌入式Android项目设计与开发 第八章 服务 —— 服务的概念 服务的概念 服务(Service)是Android中的四大组件之一,它能够长期在后台运行且不提供用户界面。即使用户切到另一应用程序,服务仍可以在后台运行。 服务...

    Google.Android开发入门与实战

     《Android开发入门与实战》内容上涵盖了用Android开发的大部分场景,从Android基础介绍、环境搭建、SDK介绍、Market使用,到应用剖析、组件介绍、实例演示等方面。从技术实现上,讲解了5个Android平台下的完整综合...

    java/android 开发面试题

    如何启用Service,如何停用Service。(Edited by Sodino) 9. 注册广播有几种方式,这些方式有何优缺点?请谈谈Android引入广播机制的用意。 10. 请解释下在单线程模型中Message、Handler、Message Queue、Looper之间...

    Google Android开发入门与实战的代码

    Google Android开发入门与实战的代码 1章 掀起你的盖头来——初识Android. 1 1.1 认识Android 1 1.2 Android的背景 2 1.2.1 Android的历史 2 1.2.2 Android的发展 2 1.3 我的Android我做主 2 ...

    黑马程序员 安卓学院 万元哥项目经理 分享220个代码实例

    |--aidl调用系统service未公开的方法挂电话 |--aidl调用系统未公开的方法代码示例2 |--android dp和px之间转换 |--android INSTALL_PARSE_FAILED_MANIFEST_MALFORMED |--android root下禁用组件 |--android 判断网络...

    Android入门.doc

    2. Android 开发环境的搭建 JDK 的安装(本文基于 JDK6) Android SDK 的安装 Eclipse 集成开发环境 目录 版本: 1.0 更新日期: 2010-10-24 8:49 4 4 4 4 5 3. 第一个 Android 应用程序的...

    Android核心设计思想分析

    Android核心分析(21)----Android应用框架之AndroidApplication.......................88 Android核心分析(22)-----Android应用框架之Activity..........................................93 Android核心分析...

Global site tag (gtag.js) - Google Analytics