@Test public void registerLifecycleCallbacksShouldThrowIfNotCalledCreate() { Activity activity = Mockito.mock(Activity.class); BackstackDelegate backstackDelegate = new BackstackDelegate(); try { backstackDelegate.registerForLifecycleCallbacks(activity); Assert.fail(); } catch(IllegalStateException e) { } }
@TargetApi(14) public void registerForLifecycleCallbacks(@Nonnull final Activity activity) { if(activity == null) { throw new NullPointerException("Activity is null"); } @SuppressWarnings("unused") Backstack backstack = getBackstack(); final Application application = activity.getApplication(); application.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() { @Override public void onActivityCreated(Activity a, Bundle savedInstanceState) { } @Override public void onActivityStarted(Activity a) { if(activity == a) { } } @Override public void onActivityResumed(Activity a) { if(activity == a) { onPostResume(); } } @Override public void onActivityPaused(Activity a) { if(activity == a) { onPause(); } } @Override public void onActivityStopped(Activity a) { if(activity == a) { } } @Override public void onActivitySaveInstanceState(Activity a, Bundle outState) { if(activity == a) { onSaveInstanceState(outState); } } @Override public void onActivityDestroyed(Activity a) { if(activity == a) { onDestroy(); application.unregisterActivityLifecycleCallbacks(this); } } }); }
BackstackDelegate { @TargetApi(14) public void registerForLifecycleCallbacks(@Nonnull final Activity activity) { if(activity == null) { throw new NullPointerException("Activity is null"); } @SuppressWarnings("unused") Backstack backstack = getBackstack(); final Application application = activity.getApplication(); application.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() { @Override public void onActivityCreated(Activity a, Bundle savedInstanceState) { } @Override public void onActivityStarted(Activity a) { if(activity == a) { } } @Override public void onActivityResumed(Activity a) { if(activity == a) { onPostResume(); } } @Override public void onActivityPaused(Activity a) { if(activity == a) { onPause(); } } @Override public void onActivityStopped(Activity a) { if(activity == a) { } } @Override public void onActivitySaveInstanceState(Activity a, Bundle outState) { if(activity == a) { onSaveInstanceState(outState); } } @Override public void onActivityDestroyed(Activity a) { if(activity == a) { onDestroy(); application.unregisterActivityLifecycleCallbacks(this); } } }); } }
BackstackDelegate { @TargetApi(14) public void registerForLifecycleCallbacks(@Nonnull final Activity activity) { if(activity == null) { throw new NullPointerException("Activity is null"); } @SuppressWarnings("unused") Backstack backstack = getBackstack(); final Application application = activity.getApplication(); application.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() { @Override public void onActivityCreated(Activity a, Bundle savedInstanceState) { } @Override public void onActivityStarted(Activity a) { if(activity == a) { } } @Override public void onActivityResumed(Activity a) { if(activity == a) { onPostResume(); } } @Override public void onActivityPaused(Activity a) { if(activity == a) { onPause(); } } @Override public void onActivityStopped(Activity a) { if(activity == a) { } } @Override public void onActivitySaveInstanceState(Activity a, Bundle outState) { if(activity == a) { onSaveInstanceState(outState); } } @Override public void onActivityDestroyed(Activity a) { if(activity == a) { onDestroy(); application.unregisterActivityLifecycleCallbacks(this); } } }); } BackstackDelegate();  BackstackDelegate(@Nullable StateChanger stateChanger); }
BackstackDelegate { @TargetApi(14) public void registerForLifecycleCallbacks(@Nonnull final Activity activity) { if(activity == null) { throw new NullPointerException("Activity is null"); } @SuppressWarnings("unused") Backstack backstack = getBackstack(); final Application application = activity.getApplication(); application.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() { @Override public void onActivityCreated(Activity a, Bundle savedInstanceState) { } @Override public void onActivityStarted(Activity a) { if(activity == a) { } } @Override public void onActivityResumed(Activity a) { if(activity == a) { onPostResume(); } } @Override public void onActivityPaused(Activity a) { if(activity == a) { onPause(); } } @Override public void onActivityStopped(Activity a) { if(activity == a) { } } @Override public void onActivitySaveInstanceState(Activity a, Bundle outState) { if(activity == a) { onSaveInstanceState(outState); } } @Override public void onActivityDestroyed(Activity a) { if(activity == a) { onDestroy(); application.unregisterActivityLifecycleCallbacks(this); } } }); } BackstackDelegate();  BackstackDelegate(@Nullable StateChanger stateChanger); void setKeyFilter(@Nonnull KeyFilter keyFilter); void setKeyParceler(@Nonnull KeyParceler keyParceler); void setStateClearStrategy(@Nonnull Backstack.StateClearStrategy stateClearStrategy); void setScopedServices(@Nullable Activity activity, @Nonnull ScopedServices scopedServices); void setGlobalServices(@Nullable Activity activity, @Nonnull GlobalServices globalServices); void setGlobalServices(@Nullable Activity activity, @Nonnull GlobalServices.Factory globalServiceFactory); void addStateChangeCompletionListener(@Nonnull Backstack.CompletionListener stateChangeCompletionListener); @SuppressWarnings("StringEquality") void setPersistenceTag(@Nonnull String persistenceTag); @TargetApi(14) void registerForLifecycleCallbacks(@Nonnull final Activity activity); void onCreate(@Nullable Bundle savedInstanceState, @Nullable Object nonConfigurationInstance, @Nonnull List<?> initialKeys); void setStateChanger(@Nullable StateChanger stateChanger); NonConfigurationInstance onRetainCustomNonConfigurationInstance(); boolean onBackPressed(); void onSaveInstanceState(@Nonnull Bundle outState); void onPostResume(); void onPause(); void onDestroy(); void persistViewToState(@Nullable View view); void restoreViewFromState(@Nonnull View view); @Nonnull SavedState getSavedState(@Nonnull Object key); boolean hasScope(@Nonnull String scopeTag); boolean hasService(@Nonnull ScopeKey scopeKey, @Nonnull String serviceTag); boolean hasService(@Nonnull String scopeTag, @Nonnull String serviceTag); @Nonnull T getService(@Nonnull ScopeKey scopeKey, @Nonnull String serviceTag); @Nonnull T getService(@Nonnull String scopeTag, @Nonnull String serviceTag); boolean canFindService(@Nonnull String serviceTag); @Nonnull T lookupService(@Nonnull String serviceTag); @Nonnull List<String> findScopesForKey(@Nonnull Object key, @Nonnull ScopeLookupMode lookupMode); boolean canFindFromScope(@Nonnull String scopeTag, @Nonnull String serviceTag); boolean canFindFromScope(@Nonnull String scopeTag, @Nonnull String serviceTag, @Nonnull ScopeLookupMode lookupMode); @Nonnull T lookupFromScope(@Nonnull String scopeTag, @Nonnull String serviceTag); @Nonnull T lookupFromScope(@Nonnull String scopeTag, @Nonnull String serviceTag, @Nonnull ScopeLookupMode lookupMode); @Nonnull Backstack getBackstack(); }
BackstackDelegate { @TargetApi(14) public void registerForLifecycleCallbacks(@Nonnull final Activity activity) { if(activity == null) { throw new NullPointerException("Activity is null"); } @SuppressWarnings("unused") Backstack backstack = getBackstack(); final Application application = activity.getApplication(); application.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() { @Override public void onActivityCreated(Activity a, Bundle savedInstanceState) { } @Override public void onActivityStarted(Activity a) { if(activity == a) { } } @Override public void onActivityResumed(Activity a) { if(activity == a) { onPostResume(); } } @Override public void onActivityPaused(Activity a) { if(activity == a) { onPause(); } } @Override public void onActivityStopped(Activity a) { if(activity == a) { } } @Override public void onActivitySaveInstanceState(Activity a, Bundle outState) { if(activity == a) { onSaveInstanceState(outState); } } @Override public void onActivityDestroyed(Activity a) { if(activity == a) { onDestroy(); application.unregisterActivityLifecycleCallbacks(this); } } }); } BackstackDelegate();  BackstackDelegate(@Nullable StateChanger stateChanger); void setKeyFilter(@Nonnull KeyFilter keyFilter); void setKeyParceler(@Nonnull KeyParceler keyParceler); void setStateClearStrategy(@Nonnull Backstack.StateClearStrategy stateClearStrategy); void setScopedServices(@Nullable Activity activity, @Nonnull ScopedServices scopedServices); void setGlobalServices(@Nullable Activity activity, @Nonnull GlobalServices globalServices); void setGlobalServices(@Nullable Activity activity, @Nonnull GlobalServices.Factory globalServiceFactory); void addStateChangeCompletionListener(@Nonnull Backstack.CompletionListener stateChangeCompletionListener); @SuppressWarnings("StringEquality") void setPersistenceTag(@Nonnull String persistenceTag); @TargetApi(14) void registerForLifecycleCallbacks(@Nonnull final Activity activity); void onCreate(@Nullable Bundle savedInstanceState, @Nullable Object nonConfigurationInstance, @Nonnull List<?> initialKeys); void setStateChanger(@Nullable StateChanger stateChanger); NonConfigurationInstance onRetainCustomNonConfigurationInstance(); boolean onBackPressed(); void onSaveInstanceState(@Nonnull Bundle outState); void onPostResume(); void onPause(); void onDestroy(); void persistViewToState(@Nullable View view); void restoreViewFromState(@Nonnull View view); @Nonnull SavedState getSavedState(@Nonnull Object key); boolean hasScope(@Nonnull String scopeTag); boolean hasService(@Nonnull ScopeKey scopeKey, @Nonnull String serviceTag); boolean hasService(@Nonnull String scopeTag, @Nonnull String serviceTag); @Nonnull T getService(@Nonnull ScopeKey scopeKey, @Nonnull String serviceTag); @Nonnull T getService(@Nonnull String scopeTag, @Nonnull String serviceTag); boolean canFindService(@Nonnull String serviceTag); @Nonnull T lookupService(@Nonnull String serviceTag); @Nonnull List<String> findScopesForKey(@Nonnull Object key, @Nonnull ScopeLookupMode lookupMode); boolean canFindFromScope(@Nonnull String scopeTag, @Nonnull String serviceTag); boolean canFindFromScope(@Nonnull String scopeTag, @Nonnull String serviceTag, @Nonnull ScopeLookupMode lookupMode); @Nonnull T lookupFromScope(@Nonnull String scopeTag, @Nonnull String serviceTag); @Nonnull T lookupFromScope(@Nonnull String scopeTag, @Nonnull String serviceTag, @Nonnull ScopeLookupMode lookupMode); @Nonnull Backstack getBackstack();  }