/** * Deactivate the current activity, find the next one from our ActivityMapper, and start it. * * <p>The current activity's widget will be hidden immediately, which can cause flicker if the * next activity provides its widget asynchronously. That can be minimized by decent caching. * Perenially slow activities might mitigate this by providing a widget immediately, with some * kind of "loading" treatment. */ public void onPlaceChange(PlaceChangeEvent event) { Activity nextActivity = getNextActivity(event); Throwable caughtOnStop = null; Throwable caughtOnCancel = null; Throwable caughtOnStart = null; if (nextActivity == null) { nextActivity = NULL_ACTIVITY; } if (currentActivity.equals(nextActivity)) { return; } if (startingNext) { // The place changed again before the new current activity showed its // widget caughtOnCancel = tryStopOrCancel(false); currentActivity = NULL_ACTIVITY; startingNext = false; } else if (!currentActivity.equals(NULL_ACTIVITY)) { showWidget(null); /* * Kill off the activity's handlers, so it doesn't have to worry about * them accidentally firing as a side effect of its tear down */ stopperedEventBus.removeHandlers(); caughtOnStop = tryStopOrCancel(true); } currentActivity = nextActivity; if (currentActivity.equals(NULL_ACTIVITY)) { showWidget(null); } else { startingNext = true; caughtOnStart = tryStart(); } if (caughtOnStart != null || caughtOnCancel != null || caughtOnStop != null) { Set<Throwable> causes = new LinkedHashSet<Throwable>(); if (caughtOnStop != null) { causes.add(caughtOnStop); } if (caughtOnCancel != null) { causes.add(caughtOnCancel); } if (caughtOnStart != null) { causes.add(caughtOnStart); } throw new UmbrellaException(causes); } }
private Throwable tryStopOrCancel(boolean stop) { Throwable caughtOnStop = null; try { if (stop) { currentActivity.onStop(); } else { currentActivity.onCancel(); } } catch (Throwable t) { caughtOnStop = t; } finally { /* * Kill off the handlers again in case it was naughty and added new ones * during onstop or oncancel */ stopperedEventBus.removeHandlers(); } return caughtOnStop; }