Android 开发文档 程序基础——Shutting down components
2010-06-19 10:51
429 查看
content provider只会在回应ContentReslover发出的请求时激活,而broadcast
receiver只在回应广播消息时激活,所以没有必要关闭这些组件。
另一方面,activity用来生成用户界面,长时间的与用户对话,甚至空闲时也保持活动,只要对话还在继续。相似的,service也会保持长时
间的运行。所以android提供了方法来关闭activity和service。
activity可以通过调用finish()来关闭。一个activity可以通过调用finishActivty()关闭另一个
activty(它通过startActivityForResult()
运行起来的
)。
service可以通过调用自身的stopSelf()来停止,或者Context.stopService().
转自我的android博客
from a ContentResolver. And a broadcast receiver is active only while
it’s responding to a broadcast message. So there’s no need to
explicitly shut down these components.
Activities, on the other hand, provide the user interface. They’re
in a long-running conversation with the user and may remain active,
even when idle, as long as the conversation continues. Similarly,
services may also remain running for a long time. So Android has
methods to shut down activities and services in an orderly way:
An activity can be shut down by calling its finish()
method. One activity
can shut down another activity (one it started with startActivityForResult()
) by
calling finishActivity()
.
A service can be stopped by calling its stopSelf()
method, or by calling Context.stopService()
.
Components might also be shut down by the system when they are no
longer being used or when Android must reclaim memory for more active
components. A later section, Component Lifecycles, discusses this
possibility and its ramifications in more detail.
receiver只在回应广播消息时激活,所以没有必要关闭这些组件。
另一方面,activity用来生成用户界面,长时间的与用户对话,甚至空闲时也保持活动,只要对话还在继续。相似的,service也会保持长时
间的运行。所以android提供了方法来关闭activity和service。
activity可以通过调用finish()来关闭。一个activity可以通过调用finishActivty()关闭另一个
activty(它通过startActivityForResult()
运行起来的
)。
service可以通过调用自身的stopSelf()来停止,或者Context.stopService().
转自我的android博客
原文
Shutting down components
A content provider is active only while it’s responding to a requestfrom a ContentResolver. And a broadcast receiver is active only while
it’s responding to a broadcast message. So there’s no need to
explicitly shut down these components.
Activities, on the other hand, provide the user interface. They’re
in a long-running conversation with the user and may remain active,
even when idle, as long as the conversation continues. Similarly,
services may also remain running for a long time. So Android has
methods to shut down activities and services in an orderly way:
An activity can be shut down by calling its finish()
method. One activity
can shut down another activity (one it started with startActivityForResult()
) by
calling finishActivity()
.
A service can be stopped by calling its stopSelf()
method, or by calling Context.stopService()
.
Components might also be shut down by the system when they are no
longer being used or when Android must reclaim memory for more active
components. A later section, Component Lifecycles, discusses this
possibility and its ramifications in more detail.
相关文章推荐
- Android 开发文档 之程序基础Application Fundamentals
- Android 开发文档 程序基础 ——activity组件
- Android 开发文档 程序基础——Activities and Tasks
- Android 开发文档 程序基础 ——Services组件
- Android 开发文档 程序基础 ——Broadcast receivers组件
- Android 开发文档 程序基础——Affinities and new tasks
- Android 开发文档 程序基础 ——Content providers组件
- Android开发基础——真机测试错误,ADB启动不了,程序安装不了,the connection to adb is down,INSTALL_CANCELED_BY_USER...
- Android 开发文档 程序基础——Activating components: intents
- Android 开发文档 程序基础——The manifest file
- Android 开发文档 程序基础——Intent filters
- android activity开发文档翻译 - 1 - 基础篇
- Android程序开发0基础教程(一)
- Eclipse开发Java和Android程序:配置文档提示和源代码查看功能(doc和source)
- Android开发之道(4)程序框架基础
- Android核心基础-3. 开发一个Android程序-3.2. 安装、卸载程序
- Android开发之道(4)程序框架基础
- Android 开发基础系列——程序崩溃之Unable to instantiate activity ComponentInfo
- 20155305 2016-2017-2 《Java程序设计》实验四 Android程序开发基础
- Android开发的基础常识二之程序解读