Package 

Object LiveDataBus


  • 
    public class LiveDataBus
    
                        

    LiveDataBus 是一个基于 LiveData 的事件总线实现,用于在组件之间传递消息。 它支持普通消息传递和粘性消息传递,其中粘性消息在观察者注册后能够立即接收到最新的消息。

    • Field Summary

      Fields 
      Modifier and Type Field Description
      public final static LiveDataBus INSTANCE
    • Method Summary

      Modifier and Type Method Description
      final static <T extends Any> MutableLiveData<T> with(String key, Class<T> type) 获取或创建一个非粘性的 LiveData 对象。
      final static <T extends Any> MutableLiveData<T> with(String key) 获取或创建一个非粘性的 LiveData 对象。
      final static <T extends Any> MutableLiveData<T> withSticky(String key, Class<T> type) 获取或创建一个粘性的 LiveData 对象。
      final static <T extends Any> MutableLiveData<T> withSticky(String key) 获取或创建一个粘性的 LiveData 对象。
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • with

        @JvmOverloads() final static <T extends Any> MutableLiveData<T> with(String key, Class<T> type)

        获取或创建一个非粘性的 LiveData 对象。

        Parameters:
        key - 用于标识 LiveData 对象的唯一键。
        type - 可选的类型参数,用于在 Java 代码中指定 LiveData 持有的数据类型。
      • with

        @JvmOverloads() final static <T extends Any> MutableLiveData<T> with(String key)

        获取或创建一个非粘性的 LiveData 对象。

        Parameters:
        key - 用于标识 LiveData 对象的唯一键。
      • withSticky

        @JvmOverloads() final static <T extends Any> MutableLiveData<T> withSticky(String key, Class<T> type)

        获取或创建一个粘性的 LiveData 对象。

        Parameters:
        key - 用于标识 LiveData 对象的唯一键。
        type - 可选的类型参数,用于在 Java 代码中指定 LiveData 持有的数据类型。
      • withSticky

        @JvmOverloads() final static <T extends Any> MutableLiveData<T> withSticky(String key)

        获取或创建一个粘性的 LiveData 对象。

        Parameters:
        key - 用于标识 LiveData 对象的唯一键。