@AfterViews is equivalent to onCreate or onPostCreate?

末鹿安然 提交于 2019-12-12 09:59:39

问题


About Android Annotations,

@AfterViews is equivalent to onCreate or onPostCreate?

or what is the annotation equivalent for each one?

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


回答1:


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().



来源:https://stackoverflow.com/questions/33832601/afterviews-is-equivalent-to-oncreate-or-onpostcreate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!