如何在不调用覆盖onCreate的情况下显示我的anko视图?

时间:2017-12-17 11:03:29

标签: android kotlin dagger-2 android-annotations anko

这是我的观看活动LoginActivityLoginActivityUI是我的anko AnkoComponent,用于展示视图。

@EActivity//not using R.layout.activity_login 
open class LoginActivity : BaseActivity() {

    //Anko view injection with dagger2
    @Inject lateinit var ui: LoginActivityUI

    //Forced to do this and its not neat
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ui.setContentView(this)
    }


    @AfterViews
    fun afterView() {
        //Never called
        ui.setContentView(this)
    }

    @AfterInject
    fun afterInject() {

        //Called but ui not initialized
        ui.setContentView(this)
    }
}

1 个答案:

答案 0 :(得分:0)

您必须根据活动生命周期覆盖onCreate

Activity lifecycle