Kotlin:我们可以在Kotlin中使用EventBus(GreenRobot)的@Subscribe吗? [英] Kotlin: Can we use @Subscribe of EventBus (GreenRobot) in Kotlin?

查看:866
本文介绍了Kotlin:我们可以在Kotlin中使用EventBus(GreenRobot)的@Subscribe吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的onEvent如下片段,在我的Kotlin函数中捕获活动的身份验证.但是,我无法触发该onEvent.

My onEvent in a fragment as below, capturing the authentication of the activity, in my Kotlin function. However, I can't get that onEvent triggered.

@Subscribe
fun onEvent(event: AuthenticationEvent) {
    if (event.isAuthenticated) {
        startFragment(signInFragment, SignInFragment.TAG)
    } else {
        startFragment(signOutFragment, SignOutFragment.TAG)
    }
}

在我的build.gradle文件中,添加了这个

In my build.gradle file, I have add this

compile 'org.greenrobot:eventbus:3.0.0'

我需要做些什么来获取此触发器吗?

Is there anything I need to do to get this trigger?

推荐答案

要将注释处理器与Kotlin一起使用,您需要使用科特林注解处理器工具(kapt).

To use annotation processors with Kotlin, you need to use the Kotlin Annotation Processor tool (kapt).

将此添加到您的build.gradle:

apply plugin: 'kotlin-kapt'

根据GreenRobot (并由我的测试确认),这就是您的全部需要获取@Subscribe.

According to GreenRobot (and confirmed by my testing), this is all you need to get @Subscribe.

这篇关于Kotlin:我们可以在Kotlin中使用EventBus(GreenRobot)的@Subscribe吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆