@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_preso); slide=(ImageView)findViewById(R.id.slide); MainActivity.SlideChangedEvent event= EventBus.getDefault().getStickyEvent(MainActivity.SlideChangedEvent.class); if (event==null) { slide.setImageResource(R.drawable.img0); } }
@Test public void testPostStickyAndGet() throws InterruptedException { eventBus.postSticky("Sticky"); assertEquals("Sticky", eventBus.getStickyEvent(String.class)); }
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_preso); slide=(ImageView)findViewById(R.id.slide); SlidePositionEvent event= EventBus.getDefault().getStickyEvent(SlidePositionEvent.class); if (event==null) { updateSlide(); } }
@Test public void testPostStickyRemoveAll() throws InterruptedException { eventBus.postSticky("Sticky"); eventBus.postSticky(new IntTestEvent(77)); eventBus.removeAllStickyEvents(); assertNull(eventBus.getStickyEvent(String.class)); assertNull(eventBus.getStickyEvent(IntTestEvent.class)); eventBus.register(this); assertNull(lastEvent); assertEquals(0, eventCount.intValue()); }
@Test public void testPostStickyRemoveClass() throws InterruptedException { eventBus.postSticky("Sticky"); eventBus.removeStickyEvent(String.class); assertNull(eventBus.getStickyEvent(String.class)); eventBus.register(this); assertNull(lastEvent); assertEquals(0, eventCount.intValue()); }
@Test public void testPostStickyRemoveEvent() throws InterruptedException { eventBus.postSticky("Sticky"); assertTrue(eventBus.removeStickyEvent("Sticky")); assertNull(eventBus.getStickyEvent(String.class)); eventBus.register(this); assertNull(lastEvent); assertEquals(0, eventCount.intValue()); }
@Test public void testRemoveStickyEventInSubscriber() throws InterruptedException { eventBus.register(new RemoveStickySubscriber()); eventBus.postSticky("Sticky"); eventBus.register(this); assertNull(lastEvent); assertEquals(0, eventCount.intValue()); assertNull(eventBus.getStickyEvent(String.class)); }
@Test public void testPostStickyAndGet() throws InterruptedException { eventBus.postSticky("Sticky"); assertEquals("Sticky", eventBus.getStickyEvent(String.class)); }
@Test public void testPostStickyRemoveAll() throws InterruptedException { eventBus.postSticky("Sticky"); eventBus.postSticky(new IntTestEvent(77)); eventBus.removeAllStickyEvents(); assertNull(eventBus.getStickyEvent(String.class)); assertNull(eventBus.getStickyEvent(IntTestEvent.class)); eventBus.register(this); assertNull(lastEvent); assertEquals(0, eventCount.intValue()); }
@Test public void testPostStickyRemoveClass() throws InterruptedException { eventBus.postSticky("Sticky"); eventBus.removeStickyEvent(String.class); assertNull(eventBus.getStickyEvent(String.class)); eventBus.register(this); assertNull(lastEvent); assertEquals(0, eventCount.intValue()); }
@Test public void testPostStickyRemoveEvent() throws InterruptedException { eventBus.postSticky("Sticky"); assertTrue(eventBus.removeStickyEvent("Sticky")); assertNull(eventBus.getStickyEvent(String.class)); eventBus.register(this); assertNull(lastEvent); assertEquals(0, eventCount.intValue()); }
@Test public void testRemoveStickyEventInSubscriber() throws InterruptedException { eventBus.register(new RemoveStickySubscriber()); eventBus.postSticky("Sticky"); eventBus.register(this); assertNull(lastEvent); assertEquals(0, eventCount.intValue()); assertNull(eventBus.getStickyEvent(String.class)); }
/** * Gets the most recent sticky event for the given type, on the local event bus only * * @see #postSticky(Object) */ public <T> T getStickyEventLocal(Class<T> eventType) { return eventBus.getStickyEvent(eventType); }
@Override public void onPause() { if (EventBus.getDefault().getStickyEvent(IsWatchConnectedLocal.class) != null) EventBus.getDefault().removeStickyEvent(IsWatchConnectedLocal.class); super.onPause(); }
@Override public void onRestoredInstanceState(RTEditText editor) { /* * We need to process pending sticky MediaEvents once the editors are registered with the * RTManager and are fully restored. */ MediaEvent event = EventBus.getDefault().getStickyEvent(MediaEvent.class); if (event != null) { onEventMainThread(event); } }
@Override public void onDestroy() { if (EventBus.getDefault().getStickyEvent(IsWatchConnectedLocal.class) != null) EventBus.getDefault().removeStickyEvent(IsWatchConnectedLocal.class); EventBus.getDefault().unregister(this); super.onDestroy(); }
/** * 关闭粘性事件的EventBus * @param eventType 粘性事件 */ protected <C> void closeStickyEventBus(Class<C> eventType){ closeEventBus(); C stickyEvent = EventBus.getDefault().getStickyEvent(eventType); if (stickyEvent != null){ EventBus.getDefault().removeStickyEvent(stickyEvent); } }
/** * 关闭粘性事件的EventBus * @param eventType 粘性事件 */ protected <C> void closeStickyEventBus(Class<C> eventType){ closeEventBus(); C stickyEvent = EventBus.getDefault().getStickyEvent(eventType); if (stickyEvent != null){ EventBus.getDefault().removeStickyEvent(stickyEvent); } }
result = null; if (!isTransportConnected) { if (AmazModApplication.isWatchConnected || (EventBus.getDefault().getStickyEvent(IsWatchConnectedLocal.class) == null)) { AmazModApplication.isWatchConnected = false; EventBus.getDefault().removeAllStickyEvents();
if (EventBus.getDefault().getStickyEvent(IsWatchConnectedLocal.class) == null) { AmazModApplication.isWatchConnected = true; EventBus.getDefault().removeAllStickyEvents();