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)
}
}
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?
To use annotation processors with Kotlin, you need to use the Kotlin Annotation Processor tool (kapt).
Add this to your build.gradle
:
apply plugin: 'kotlin-kapt'
According to GreenRobot (and confirmed by my testing), this is all you need to get @Subscribe
.
@Subscribe
annotation is public
In the build.gradle
file add the code:
apply plugin: 'kotlin-kapt'
implementation "org.greenrobot:eventbus:3.0.0"
kapt 'org.greenrobot:eventbus-annotation-processor:3.0.1'
If you want to use Subscriber Index
, you add the code to build.gradle
too:
kapt {
arguments {
arg('eventBusIndex', 'your-package.MyEventBusIndex')
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With