启动activity

1.onCreate()

1.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.

2.Called when the activity is starting.
This is where most initialization should go:
calling setContentView(int) to inflate the activity‘s UI,
using findViewById(int) to programmatically interact with widgets in the UI,
calling managedQuery(android.net.Uri, String[], String, String[], String) to retrieve cursors for data being displayed, etc.
3.You can call finish() from within this function, in which case onDestroy() will be immediately called without any of the rest of the activity lifecycle (onStart(),onResume(), onPause(), etc) executing.
Derived classes must call through to the super class‘s implementation of this method. If they do not, an exception will be thrown.
onCreate()在一个activity启动时应被最先调用,
进行初始化,
这个函数调用完后,
这个activity并不是说就已经启动了,或者是跳到前台了。
而是还需要其他的大量工作,
我们知道:onCreate之后还有
onStart()onRestart()
实际上onStart()调用完毕了这个activity还没有完全启动,也只是前台可见
直到 onResume() 调用后这个onCreate才算终于启动。

2.onCreate中的savedInstanceState有何具体作用

在activity的生命周期中,只要离开了可见阶段,或者说失去了焦点,activity就很可能被进程终止了!被KILL掉了,这时候,就需要有种机制,能保存当时的状态,这就是savedInstanceState的作用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值