@AfterViews相当于的onCreate或onPostCreate?AfterViews、onCreate、onPostCreate

2023-09-12 05:47:39 作者:久伴情自长

关于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的方法,并把我的两个全code在相同的方法@AfterViews?

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

推荐答案

在注释活动 s时, @AfterViews 注释的方法被称为的onCreate()。在注释片段 s时, @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().