Android 的onApplyThemeResource onWindowFocusChanged onAttachedToWindow

之前看Googl提供的Android API 没有发现有onWindowFocusChanged(boolean hasFocus)这个方法,我还以为Activity的生命周期就只有那表述的7个方法而已

无意中测试的项目的时候发现了这个方法,我就随意的测试了一下,Activity 启动的时候最先调用的是这个onApplyThemeResource(Theme theme, int resid, boolean first)

方法,然后依次是:onCreate(Bundle savedInstanceState)---->onContentChanged() --->onStart() ---->onResume()----->onPostResume()---->onAttachedToWindow() ---->onWindowFocusChanged(boolean hasFocus)------>onPause()---->onWindowFocusChanged(boolean hasFocus)--->onStop() ---->onDestroy()

到这里我发现Android本身就是一个大框架,这些方法不管你使用与否,Android本身会自动去执行,想要测试这些方法也很简单,可以在这些方法里面写一些代码,然后看Activity的效果。

Activity生命周期中,onStart, onResume, onCreate都不是真正visible的时间点,真正的visible时间点是onWindowFocusChanged()函数被执行时。
从onWindowFocusChanged被执行起,用户可以与应用进行交互了,而这之前,对用户的操作需要做一点限制。一下这些都可以在这个方法内获取

this.getActionBar();
this.getApplicationContext();
this.getBaseContext();
this.getApplicationInfo();
this.getCallingPackage();
this.getChangingConfigurations();
this.getClassLoader();
this.getExternalCacheDir();
this.btnLogin.getWidth();

Android框架有很多有趣 的操作,细细的琢磨肯定能发现很多亮点。。。



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值