activity使用事项

首先看一下activity的生命周期:

 

 

There are two methods almost all subclasses of Activity will implement:

  • onCreate(Bundle) is where you initialize your activity. Most importantly, here you will usually call setContentView(int) with a layout resource defining your UI, and using findViewById(int) to retrieve the widgets in that UI that you need to interact with programmatically.
  • onPause() is where you deal with the user leaving your activity. Most importantly, any changes made by the user should at this point be committed (usually to the ContentProvider holding the data).

To be of use with Context.startActivity(), all activity classes must have a corresponding <activity> declaration in their package's AndroidManifest.xml.

 

 

有两个方法经常会被Activity的子类来实现:

 

onCreate(Bundle) 在这里你初始化你到Activity,最重要的是,在这里你应该经常调用setContentView(int),使用一个定义你到UI

的资源布局,使用 findViewById(int)  去查找你在那个资源布局中定义的widget窗体。

onPause() 在这里处理当用户离开activity的时候所需执行到操作,最重要的是任何用户作出的改变都应该在这里被提交(经常情况下是ContentProvider保持着数据)。

 

如果你要使用Context.startActivity方法,所有的activity类都必须在 AndroidManifest.xml文件到 <activity>标签中进行声明。

 

 

 an application is not in the killable state until its onStop() has returned. This impacts whenonSaveInstanceState(Bundle) may be called (it may be safely called after onPause() and allows and application to safely wait until onStop() to save persistent state.

 

一个应用程序不在可被杀死的状态,直到onStap()方法返回。这也就意味着当onPause()方法调用到时候,我们应该调用onSaveInstanceState(Bundle),这样就可以安全等待到onStop()方法去保存持续性到状态。

 

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值