Android 开发文档 程序基础——Shutting down components

content provider只会在回应ContentReslover发出的请求时激活,而broadcast 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 request 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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值