Broadcast receiver lifecycle---广播接收组件生命周期
A broadcast receiver has single callback method:--翻译:广播接收组件只有唯一一个回调方法:
When a broadcast message arrives for the receiver, Android calls its onReceive()广播接收组件 method and passes it the Intent object containing the message. The broadcast receiver is considered to be active only while it is executing this method. When onReceive() returns, it is inactive.
当消息接受者接到广播消息,Android将立刻调用广播接收组件实例的 onReceive()方法,同时,消息封装在intent对象中以参数的方式传入该方法,该方法执行过程中,该广播接收组件实例的状态是活动状态。广播接收组件实例的onReceive()一旦执行完毕,广播接收组件实例的状态变为非活动状态。
A process with an active broadcast receiver is protected from being killed. But a process with only inactive components can be killed by the system at any time, when the memory it consumes is needed by other processes.
翻译:活动状态的广播接收组件实例所属的进程是受系统保护的,不会被系统关闭的。但是对于非活动状态的广播接收组件实例所属的进程而言,一旦出现系统资源缺乏,为了腾出必要内存空间,系统随时可以杀死该进程。
This presents a problem when the response to a broadcast message is time consuming and, therefore, something that should be done in a separate thread, away from the main thread where other components of the user interface run. If onReceive() spawns the thread and then returns, the entire process, including the new thread, is judged to be inactive (unless other application components are active in the process), putting it in jeopardy of being killed. The solution to this problem is for onReceive() to start a service and let the service do the job, so the system knows that there is still active work being done in the process.
翻译:需要注意的是,如果说对广播消息的响应是耗时操作的话(onReceive()方法中的代码),就需要考虑脱离主线程、以独立线程方式执行对消息的响应处理,这样可以避免阻塞现象的发生(寄宿在主线程之上的其他组件实例与用户交互过程被阻塞)。如果在onReceive()方法中在当前进程中创建一个独立的线程,该方法执行完毕后,当前进程可能被系统就认定为惰性进程(如果此时进程中的其他组件实例都处于惰性状态),当前进程是随时可能被系统关闭的。对这个问题的解决方式是:在onReceive()方法中以服务的方式来处理对消息的响应,这样可以使得系统认为当前进程依然是活动状态,避免被系统杀死。
The next section has more on the vulnerability of processes to being killed.
A broadcast receiver has single callback method:--翻译:广播接收组件只有唯一一个回调方法:
void onReceive(Context curContext, Intent broadcastMsg)
When a broadcast message arrives for the receiver, Android calls its onReceive()广播接收组件 method and passes it the Intent object containing the message. The broadcast receiver is considered to be active only while it is executing this method. When onReceive() returns, it is inactive.
当消息接受者接到广播消息,Android将立刻调用广播接收组件实例的 onReceive()方法,同时,消息封装在intent对象中以参数的方式传入该方法,该方法执行过程中,该广播接收组件实例的状态是活动状态。广播接收组件实例的onReceive()一旦执行完毕,广播接收组件实例的状态变为非活动状态。
A process with an active broadcast receiver is protected from being killed. But a process with only inactive components can be killed by the system at any time, when the memory it consumes is needed by other processes.
翻译:活动状态的广播接收组件实例所属的进程是受系统保护的,不会被系统关闭的。但是对于非活动状态的广播接收组件实例所属的进程而言,一旦出现系统资源缺乏,为了腾出必要内存空间,系统随时可以杀死该进程。
This presents a problem when the response to a broadcast message is time consuming and, therefore, something that should be done in a separate thread, away from the main thread where other components of the user interface run. If onReceive() spawns the thread and then returns, the entire process, including the new thread, is judged to be inactive (unless other application components are active in the process), putting it in jeopardy of being killed. The solution to this problem is for onReceive() to start a service and let the service do the job, so the system knows that there is still active work being done in the process.
翻译:需要注意的是,如果说对广播消息的响应是耗时操作的话(onReceive()方法中的代码),就需要考虑脱离主线程、以独立线程方式执行对消息的响应处理,这样可以避免阻塞现象的发生(寄宿在主线程之上的其他组件实例与用户交互过程被阻塞)。如果在onReceive()方法中在当前进程中创建一个独立的线程,该方法执行完毕后,当前进程可能被系统就认定为惰性进程(如果此时进程中的其他组件实例都处于惰性状态),当前进程是随时可能被系统关闭的。对这个问题的解决方式是:在onReceive()方法中以服务的方式来处理对消息的响应,这样可以使得系统认为当前进程依然是活动状态,避免被系统杀死。
The next section has more on the vulnerability of processes to being killed.
发表评论
-
Intents and Intent Filters--Intent filters
2010-09-03 10:21 1361Intent filters To inform ... -
Intents and Intent Filters---Intent Resolution
2010-09-03 09:45 1196Intent Resolution Intents 可以分成 ... -
Intents and Intent Filters---Intent Objects
2010-09-02 11:15 814Intent Objects An Intent ... -
Intents and Intent Filters---序言
2010-09-01 16:06 872Intents and Intent Filters Key ... -
Application Fundamentals--Processes and lifecycles(进程生命周期)
2010-08-30 09:23 752Processes and lifecycles---进 ... -
Application Fundamentals--Service lifecycle(服务组件的生命周期)
2010-08-30 09:18 1049Service lifecycle--服务组件的生命周期 A ... -
Application Fundamentals--Coordinating activities(activity实例间协调)
2010-08-30 09:15 964Coordinating activities---activ ... -
Application Fundamentals--Saving activity state(保存activity实例的状态信息)
2010-08-27 10:06 1257Saving activity state--保存activi ... -
Application Fundamentals--Component Lifecycles(组件生命周期)
2010-08-27 09:56 959Component Lifecycles--组件生命周期 A ... -
Application Fundamentals--Thread-safe methods(线程安全方法)
2010-08-27 09:51 1253Thread-safe methods--线程安 ... -
Application Fundamentals--Remote procedure calls(远程过程调用)
2010-08-27 09:41 1290Remote procedure calls--远程过程调用 ... -
Application Fundamentals--Processes and Threads(进程与线程)
2010-08-27 09:36 990Processes and Threads--进程 ... -
Application Fundamentals--Starting tasks
2010-08-27 09:34 699Starting tasks An activity is ... -
Application Fundamentals--Clearing the stack(堆栈清理)
2010-08-27 09:28 1342Clearing the stack--堆栈清理 If th ... -
Application Fundamentals--Launch modes-启动模式
2010-08-27 09:27 1114Launch modes-启动模式 There are fo ... -
Application Fundamentals--Affinities and new tasks
2010-08-27 08:45 978Affinities and new tasks By de ... -
Application Fundamentals--Activities and Tasks
2010-08-27 08:42 787Activities and Tasks As noted ... -
Application Fundamentals--Intent 过滤器
2010-08-27 08:41 921Intent 过滤器 Intent 对象可以显式指定目标组件 ... -
Application Fundamentals--The manifest file
2010-08-27 08:40 787The manifest file Android启动应用程 ... -
Application Fundamentals--Activating components: intents(组件的激活)
2010-08-27 08:38 933Activating components: intents- ...
相关推荐
DB2 9 Database and Application Fundamentals - Academic Initiative 000-302 2011年12月版本 V8.02 Q188道。
fundamentals-of-power-electronics_2nd_erickson_full
Fundamentals-of-HVAC-Control-Systems-Malestrom.part02.rar
linux-shell-scripting-fundamentals-bash.epub
fundamentals-of-radar-signal
ios-12-programming-fundamentals-swift epub. very good
fundamentals-of-statistical-signal-processing-volume-i-estimation-theory_1
2016-fuel cell fundamentals-3rd edition.pdf
此存储库包含
Fundamentals-of-heat-and-mass-transfer 7ed.pdf ;INSTRUCTOR'S SOLUTIONS MANUAL
Az-900-Microsoft-Azure-Fundamentals-Version-16.0-It-Exam-Practice-Test.pdf
Az-900-Microsoft-Azure-Fundamentals-Version-19.1-It-Exam-Practice-Test.pdf
Electric Machinery Fundamentals - 5th Ed
Data Warehousing Fundamentals-2001
安卓应用开发教程配套实验教程!课程网址:https://developer.android.com/courses/fundamentals-training/toc-v2
ruby-oo-fundamentals-attribute-accessors-lab-wdc01-seng-ft-060120-源码.rar
ruby-oo-fundamentals-attribute-accessors-lab-sea01-seng-ft-071320-master.rar
Kubernetes 基础课程个人笔记整理包含内容:01.课程介绍 02. KUBERNETES的基础 03.安装与配置 04. KUBERNETES 架构 05. API和访问(ACCESS) 06. API对象(API Objects) 07.通过部署管理状态(managing state with ...
vuejs-components-fundamentals-源码.rar