- 浏览: 1843305 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (665)
- 闲话 (17)
- ruby (1)
- javascript (40)
- linux (7)
- android (22)
- 开发过程 (11)
- 哥也读读源代码 (13)
- JVM (1)
- ant (2)
- Hibernate (3)
- jboss (3)
- web service (17)
- https (4)
- java基础 (17)
- spring (7)
- servlet (3)
- 杂记 (39)
- struts2 (10)
- logback (4)
- 多线程 (2)
- 系统诊断 (9)
- UI (4)
- json (2)
- Java EE (7)
- eclipse相关 (4)
- JMS (1)
- maven (19)
- 版本管理 (7)
- sso (1)
- ci (1)
- 设计 (18)
- 戒烟 (4)
- http (9)
- 计划 (4)
- HTML5 (3)
- chrome extensions (5)
- tomcat源码阅读 (4)
- httpd (5)
- MongoDB (3)
- node (2)
最新评论
-
levin_china:
勾选了,还是找不到
用spring annotation声明的bean,当打包在jar中时,无法被扫描到 -
GGGGeek:
我用的maven-3.5.0,还没有遇到这种情况,使用jar ...
用spring annotation声明的bean,当打包在jar中时,无法被扫描到 -
GGGGeek:
受益匪浅,从组织项目结构,到技术细节,讲的很到位,只是博主不再 ...
一个多maven项目聚合的实例 -
Aaron-Joe-William:
<?xml version="1.0" ...
hibernate逆向工程 -
li272355201:
http://archive.apache.org/dist/ ...
tomcat源码阅读(一)——环境搭建
1、生命周期方法onSaveInstanceState()是在什么时候调用?是当一个Activity变成“有可能被销毁”的状态的时候被android框架调用的,包括:
1.1、用户按下HOME键
1.2、长按HOME键,选择其他程序
1.3、按下电源按键
1.4、在Activity中开启一个新的Activity时
1.5、横竖屏翻转时
但是,如果是用户按下BACK键,则当前的Activity会被销毁,并从back stack中移除,这种情况下,onSaveInstanceState()方法是不会被调用的
2、至于onRestoreInstanceState()方法,需要注意的是,onSaveInstanceState()方法和onRestoreInstanceState()方法不一定是成对的被调用的,onRestoreInstanceState()被调用的前提是,activity“确实”被系统销毁了,而如果仅仅是停留在有这种可能性的情况下,则该方法不会被调用,例如,当正在显示activity的时候,用户按下HOME键回到主界面,然后用户紧接着又返回到activity,这种情况下activity一般不会因为内存的原因被系统销毁,故activity的onRestoreInstanceState()方法不会被执行
另外,onRestoreInstanceState()的bundle参数也会传递到onCreate方法中,因此也可以选择在onCreate()方法中做数据还原
3、The Android operating system is a multi-user Linux system in which each application is a different user.
4、By default, the system assigns each application a unique Linux user ID (the ID is used only by the system and is unknown to the application). The system sets permissions for all the files in an application so that only the user ID assigned to that application can access them
5、Each process has its own virtual machine (VM), so an application's code runs in isolation from other applications
6、By default, every application runs in its own Linux process. Android starts the process when any of the application's components need to be executed, then shuts down the process when it's no longer needed or when the system must recover memory for other applications
7、When the system starts a component, it starts the process for that application (if it's not already running) and instantiates the classes needed for the component. For example, if your application starts the activity in the camera application that captures a photo, that activity runs in the process that belongs to the camera application, not in your application's process
8、A service runs in the main thread of its hosting process—the service does not create its own thread and does not run in a separate process (unless you specify otherwise). This means that, if your service is going to do any CPU intensive work or blocking operations (such as MP3 playback or networking), you should create a new thread within the service to do that work. By using a separate thread, you will reduce the risk of Application Not Responding (ANR) errors and the application's main thread can remain dedicated to user interaction with your activities
开启的Service,是跑在主线程里的,也就是UI线程。所以确实是会阻塞页面刷新的,如果操作很耗时的话,甚至会引发ANR。所以如果是一个很费时的操作,需要手工地开启新线程。但是,如果不要求Service组件并发地处理多线程请求的话,可以用IntentService。这样的话,就不需要操心线程的事,一个附带的好处是,也不需要手动地stop这个Service。带来的坏处是,如果有多个Intent请求到这个Service,只能排队
9、The system calls onStartCommand() when another component, such as an activity, requests that the service be started, by calling startService(). Once this method executes, the service is started and can run in the background indefinitely. If you implement this, it is your responsibility to stop the service when its work is done, by calling stopSelf() or stopService()
Service一旦经过startService()方法调用运行起来,就会在后台默默运行,不会停止。所以如果开启了一个服务,记得通过stopService()或者stopSelf()方法,把服务关掉。同样的,如果这个服务是继承自IntentService,可以减少这个步骤
10、The Android system will force-stop a service only when memory is low and it must recover system resources for the activity that has user focus. If the service is bound to an activity that has user focus, then it's less likely to be killed, and if the service is declared to run in the foreground (discussed later), then it will almost never be killed. Otherwise, if the service was started and is long-running, then the system will lower its position in the list of background tasks over time and the service will become highly susceptible to killing—if your service is started, then you must design it to gracefully handle restarts by the system. If the system kills your service, it restarts it as soon as resources become available again (though this also depends on the value you return from onStartCommand(), as discussed later)
系统如果出于回收资源的目的,把服务给停掉了,那么当资源重新可用的时候,系统会重新启动这个服务
11、A services runs in the same process as the application in which it is declared and in the main thread of that application, by default. So, if your service performs intensive or blocking operations while the user interacts with an activity from the same application, the service will slow down activity performance. To avoid impacting application performance, you should start a new thread inside the service
12、The IntentService does the following:
Creates a default worker thread that executes all intents delivered to onStartCommand() separate from your application's main thread.
Creates a work queue that passes one intent at a time to your onHandleIntent() implementation, so you never have to worry about multi-threading.
Stops the service after all start requests have been handled, so you never have to call stopSelf().
Provides default implementation of onBind() that returns null.
Provides a default implementation of onStartCommand() that sends the intent to the work queue and then to your onHandleIntent() implementation.
如果不需要考虑处理并发请求,让Service继承自IntentService是一个很好的选择
13、That's all you need: a constructor and an implementation of onHandleIntent()
构造方法中的String是为了个新线程命名,通常是这样的:
14、As you saw in the previous section, using IntentService makes your implementation of a started service very simple. If, however, you require your service to perform multi-threading (instead of processing start requests through a work queue), then you can extend the Service class to handle each intent
15、Notice that the onStartCommand() method must return an integer. The integer is a value that describes how the system should continue the service in the event that the system kills it (as discussed above, the default implementation for IntentService handles this for you, though you are able to modify it). The return value from onStartCommand() must be one of the following constants:
START_NOT_STICKY
If the system kills the service after onStartCommand() returns, do not recreate the service, unless there are pending intents to deliver. This is the safest option to avoid running your service when not necessary and when your application can simply restart any unfinished jobs.
START_STICKY
If the system kills the service after onStartCommand() returns, recreate the service and call onStartCommand(), but do not redeliver the last intent. Instead, the system calls onStartCommand() with a null intent, unless there were pending intents to start the service, in which case, those intents are delivered. This is suitable for media players (or similar services) that are not executing commands, but running indefinitely and waiting for a job.
START_REDELIVER_INTENT
If the system kills the service after onStartCommand() returns, recreate the service and call onStartCommand() with the last intent that was delivered to the service. Any pending intents are delivered in turn. This is suitable for services that are actively performing a job that should be immediately resumed, such as downloading a file.
16、The startService() method returns immediately and the Android system calls the service's onStartCommand() method. If the service is not already running, the system first calls onCreate(), then calls onStartCommand()
17、A foreground service is a service that's considered to be something the user is actively aware of and thus not a candidate for the system to kill when low on memory. A foreground service must provide a notification for the status bar, which is placed under the "Ongoing" heading, which means that the notification cannot be dismissed unless the service is either stopped or removed from the foreground
18、Service的生命周期方法包括onCreate() onStartCommand() onDestroy()
1.1、用户按下HOME键
1.2、长按HOME键,选择其他程序
1.3、按下电源按键
1.4、在Activity中开启一个新的Activity时
1.5、横竖屏翻转时
但是,如果是用户按下BACK键,则当前的Activity会被销毁,并从back stack中移除,这种情况下,onSaveInstanceState()方法是不会被调用的
2、至于onRestoreInstanceState()方法,需要注意的是,onSaveInstanceState()方法和onRestoreInstanceState()方法不一定是成对的被调用的,onRestoreInstanceState()被调用的前提是,activity“确实”被系统销毁了,而如果仅仅是停留在有这种可能性的情况下,则该方法不会被调用,例如,当正在显示activity的时候,用户按下HOME键回到主界面,然后用户紧接着又返回到activity,这种情况下activity一般不会因为内存的原因被系统销毁,故activity的onRestoreInstanceState()方法不会被执行
另外,onRestoreInstanceState()的bundle参数也会传递到onCreate方法中,因此也可以选择在onCreate()方法中做数据还原
3、The Android operating system is a multi-user Linux system in which each application is a different user.
4、By default, the system assigns each application a unique Linux user ID (the ID is used only by the system and is unknown to the application). The system sets permissions for all the files in an application so that only the user ID assigned to that application can access them
5、Each process has its own virtual machine (VM), so an application's code runs in isolation from other applications
6、By default, every application runs in its own Linux process. Android starts the process when any of the application's components need to be executed, then shuts down the process when it's no longer needed or when the system must recover memory for other applications
7、When the system starts a component, it starts the process for that application (if it's not already running) and instantiates the classes needed for the component. For example, if your application starts the activity in the camera application that captures a photo, that activity runs in the process that belongs to the camera application, not in your application's process
8、A service runs in the main thread of its hosting process—the service does not create its own thread and does not run in a separate process (unless you specify otherwise). This means that, if your service is going to do any CPU intensive work or blocking operations (such as MP3 playback or networking), you should create a new thread within the service to do that work. By using a separate thread, you will reduce the risk of Application Not Responding (ANR) errors and the application's main thread can remain dedicated to user interaction with your activities
开启的Service,是跑在主线程里的,也就是UI线程。所以确实是会阻塞页面刷新的,如果操作很耗时的话,甚至会引发ANR。所以如果是一个很费时的操作,需要手工地开启新线程。但是,如果不要求Service组件并发地处理多线程请求的话,可以用IntentService。这样的话,就不需要操心线程的事,一个附带的好处是,也不需要手动地stop这个Service。带来的坏处是,如果有多个Intent请求到这个Service,只能排队
9、The system calls onStartCommand() when another component, such as an activity, requests that the service be started, by calling startService(). Once this method executes, the service is started and can run in the background indefinitely. If you implement this, it is your responsibility to stop the service when its work is done, by calling stopSelf() or stopService()
Service一旦经过startService()方法调用运行起来,就会在后台默默运行,不会停止。所以如果开启了一个服务,记得通过stopService()或者stopSelf()方法,把服务关掉。同样的,如果这个服务是继承自IntentService,可以减少这个步骤
10、The Android system will force-stop a service only when memory is low and it must recover system resources for the activity that has user focus. If the service is bound to an activity that has user focus, then it's less likely to be killed, and if the service is declared to run in the foreground (discussed later), then it will almost never be killed. Otherwise, if the service was started and is long-running, then the system will lower its position in the list of background tasks over time and the service will become highly susceptible to killing—if your service is started, then you must design it to gracefully handle restarts by the system. If the system kills your service, it restarts it as soon as resources become available again (though this also depends on the value you return from onStartCommand(), as discussed later)
系统如果出于回收资源的目的,把服务给停掉了,那么当资源重新可用的时候,系统会重新启动这个服务
11、A services runs in the same process as the application in which it is declared and in the main thread of that application, by default. So, if your service performs intensive or blocking operations while the user interacts with an activity from the same application, the service will slow down activity performance. To avoid impacting application performance, you should start a new thread inside the service
12、The IntentService does the following:
Creates a default worker thread that executes all intents delivered to onStartCommand() separate from your application's main thread.
Creates a work queue that passes one intent at a time to your onHandleIntent() implementation, so you never have to worry about multi-threading.
Stops the service after all start requests have been handled, so you never have to call stopSelf().
Provides default implementation of onBind() that returns null.
Provides a default implementation of onStartCommand() that sends the intent to the work queue and then to your onHandleIntent() implementation.
如果不需要考虑处理并发请求,让Service继承自IntentService是一个很好的选择
13、That's all you need: a constructor and an implementation of onHandleIntent()
构造方法中的String是为了个新线程命名,通常是这样的:
public MyService(){ super("MyServiceThread"); }
14、As you saw in the previous section, using IntentService makes your implementation of a started service very simple. If, however, you require your service to perform multi-threading (instead of processing start requests through a work queue), then you can extend the Service class to handle each intent
15、Notice that the onStartCommand() method must return an integer. The integer is a value that describes how the system should continue the service in the event that the system kills it (as discussed above, the default implementation for IntentService handles this for you, though you are able to modify it). The return value from onStartCommand() must be one of the following constants:
START_NOT_STICKY
If the system kills the service after onStartCommand() returns, do not recreate the service, unless there are pending intents to deliver. This is the safest option to avoid running your service when not necessary and when your application can simply restart any unfinished jobs.
START_STICKY
If the system kills the service after onStartCommand() returns, recreate the service and call onStartCommand(), but do not redeliver the last intent. Instead, the system calls onStartCommand() with a null intent, unless there were pending intents to start the service, in which case, those intents are delivered. This is suitable for media players (or similar services) that are not executing commands, but running indefinitely and waiting for a job.
START_REDELIVER_INTENT
If the system kills the service after onStartCommand() returns, recreate the service and call onStartCommand() with the last intent that was delivered to the service. Any pending intents are delivered in turn. This is suitable for services that are actively performing a job that should be immediately resumed, such as downloading a file.
16、The startService() method returns immediately and the Android system calls the service's onStartCommand() method. If the service is not already running, the system first calls onCreate(), then calls onStartCommand()
17、A foreground service is a service that's considered to be something the user is actively aware of and thus not a candidate for the system to kill when low on memory. A foreground service must provide a notification for the status bar, which is placed under the "Ongoing" heading, which means that the notification cannot be dismissed unless the service is either stopped or removed from the foreground
18、Service的生命周期方法包括onCreate() onStartCommand() onDestroy()
发表评论
-
最近半个月开发小结
2011-12-05 22:16 13141、有一个方法,有一段 ... -
Tasks and Back Stack
2011-11-22 23:47 1183Even though the activities may ... -
上周开发过程中几个简单问题的总结
2011-11-21 13:18 1363上周开发中组员遇到几个问题,都不是大问题,但都耽搁了一些时间。 ... -
android培训文档提纲(三)
2011-11-12 23:47 17651、Activity和Service组件是Context的子类 ... -
android的Log组件和logcat命令
2011-11-12 23:03 6324项目进入开发阶段了, ... -
android培训文档提纲(二)
2011-11-07 21:10 1664一、Each Activity can make an ... -
android培训文档提纲(一)
2011-10-23 14:05 1607最近项目快要进入开发 ... -
顶部有一排按钮,最底下还有FooterView的ListView页面
2011-08-13 15:46 3302先上效果图: 下面详细说说这个页面是怎么做出来的: 1、 ... -
实现屏幕下方展示的TAB分页
2011-08-09 23:22 2176这篇博客是参考helloandroid兄的腾讯微博应用,我整理 ... -
PendingIntent
2011-08-08 16:02 1562在开发SMS等应用时,有时调用相关的API会要求提供一个类型为 ... -
android数据持久化总结
2011-08-06 12:23 19211、 通过Context.getSharedPreferenc ... -
intent and service
2011-08-04 00:07 1424明天才开始讨论包需求 ... -
最近两周android总结
2011-08-01 23:42 1616最近2周预研做得差不多 ... -
没有单元测试,怎能写代码
2011-07-25 17:56 1573项目前期的技术点预研完成了,最近开始做原型开发。 之前没有在 ... -
android process and thread
2011-07-18 16:31 1695前三周android预研中,把可能用到的技术点都识别了,并完成 ... -
android第三周小结
2011-07-18 10:16 13641. 系统自带的通讯录应用,联系人名单保存在data/data ... -
onPause()方法的特殊性
2011-07-15 17:11 2929onPause(), onStop(), onDestroy( ... -
activity存在的三种状态
2011-07-15 16:44 1775An activity can exist in essent ... -
android第二周小结
2011-07-14 10:50 11641. 做了短信侦听的Broadca ... -
android一周小结
2011-07-04 21:26 1232做了一周android预研,总结以下几条: 1. 用DDMS ...
相关推荐
"软件项目开发的全套文档提纲模板"旨在提供一个结构化的框架,帮助开发者和项目经理有效地组织和编写各种必要的文档。以下是对这个提纲模板中可能包含的主要知识点的详细解释: 1. **项目启动文档**: - 项目背景...
软件项目开发的全套文档提纲 软件项目开发的全套文档提纲\项目开发总结报告(GB8567——88).doc 软件项目开发的全套文档提纲\用户手册(GB8567——88).doc 软件项目开发的全套文档提纲\操作手册(GB8567——88)....
以下是对"软件项目开发的全套文档提纲"的详细解释: 1. **项目启动文档 (Project Initiation Document, PID)** - PID是项目的起点,它定义了项目的目标、范围、预期成果以及初步的时间线和预算。 2. **需求分析...
软件开发项目文档的应用是非常广泛的,例如,软件开发项目文档可以作为项目团队的参考文档,软件开发项目文档可以作为项目团队与客户之间的交流工具,软件开发项目文档可以作为项目团队的培训文档等。 软件开发项目...
这个提纲主要关注的是底层部分,特别是针对ARM平台的Android移植与驱动核心开发。 1. **Android系统体系及移植相关工具** - **Android操作系统体系结构**:Android的核心包括Linux内核,负责硬件管理,以及Dalvik...
"项目开发的全套文档提纲doc"涵盖了项目从启动到结束各个阶段所需的主要文档,旨在为团队提供清晰的指导和结构化的工作流程。以下是这套文档提纲中所包含的知识点详解: 1. 可行性研究报告:这是项目启动阶段的第一...
清华大学培训班培训提纲清华大学培训班培训提纲清华大学培训班培训提纲清华大学培训班培训提纲
《高管财务知识培训》提纲主要涵盖了财务报表的解读、财务指标分析以及绩效分析三个核心领域,旨在提升高级管理人员的财务理解和决策能力。 首先,提纲深入解析了资产负债表和利润表这两个关键财务报表。资产负债表...
"软件项目开发全套文档提纲"涵盖了软件工程中的各个重要阶段,旨在提供一个清晰、系统化的指导框架,以帮助团队成员理解项目的整体结构和各个阶段的目标。以下是对这套文档模板各部分的详细解释: 1. **项目启动...
垃圾分类培训提纲.doc