public class LiveDataBus { private Map<String, MutableLiveData<Object>> bus; private static LiveDataBus liveDataBus = new LiveDataBus(); private LiveDataBus(){ bus = new HashMap<>(); } public static LiveDataBus getInstance(){ return liveDataBus; } public synchronized <T> MutableLiveData<T> with(String key, Class<T> type, boolean sticky){ if (bus.containsKey(key)){ if (sticky){ bus.put(key, new MutableLiveData<Object>()); }else { bus.put(key, new NonStickyMutableLiveData<Object>()); } } return (MutableLiveData<T>) bus.get(key); }}