本文介绍了@AfterViews 相当于 onCreate 还是 onPostCreate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

关于 Android 注释,

About Android Annotations,

@AfterViews 相当于 onCreate 还是 onPostCreate?

@AfterViews is equivalent to onCreate or onPostCreate?

或者每个注释的等效注释是什么?

or what is the annotation equivalent for each one?

我可以删除onCreate"和onPostCreate"方法,并将我的全部代码与@AfterViews 放在同一个方法中吗?

can i remove "onCreate" and "onPostCreate" methods and put my whole code of both in the same method with @AfterViews?

推荐答案

在带注释的 Activity 中,@AfterViews 带注释的方法在 onCreate() 中被调用.在带注释的 Fragment 中,@AfterViews 带注释的方法在 onViewCreated() 中被调用.如果您不想在创建视图之前进行初始化,您可以安全地删除您的 onCreate() 方法并在 @AfterView 的注释方法中执行所有操作.然而,AfterViews 的主要原因是调用者有机会初始化注入的视图,这些视图在 onCreate() 中尚不可用.

In annotated Activitys, the @AfterViews annotated methods are called in onCreate(). In annotated Fragments, the @AfterViews annotated methods are called in onViewCreated(). If you do not want to do initialization before views are created, you can safely remove your onCreate() method and do everything in an @AfterViews annotated method.However the main reason of AfterViews is getting a chance to the caller to initialise injected views, which are not yet available in onCreate().

这篇关于@AfterViews 相当于 onCreate 还是 onPostCreate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 14:41