问题
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 Activity
s, the @AfterViews
annotated methods are called in onCreate()
. In annotated Fragment
s, 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 @AfterView
s 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