RxBus-Kotlin-Example Using RxBus in Kotlin Projects

In this RxBus-Kotlin example, you will learn how to integrate RxBus into your project and how to use it for event publishing. Here's the step-by-step guide:

  1. Add the required dependencies and classes to your project.
  2. Once integrated, you can start publishing events using RxBus.publish(RxEvent.EventAddPerson(etPersonName.text.toString())).

MainActivity class implementation:

class MainActivity : AppCompatActivity() {
    private lateinit var disposable: Disposable

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        disposable = RxBus.listen(RxEvent.EventAddPerson::class.java)
            .subscribe { event ->
                // Handle the event
            }
    }
}
zip 文件大小:227.38KB