@Test public void attachTwice() { Loader.Callbacks<String> callbacks = mock(Loader.Callbacks.class); TestLoader<String> loader = loaderManager.init(0, TestLoader.<String>create(), callbacks); try { loaderManager.init(0, TestLoader.<String>create(), null); fail(); } catch (IllegalStateException e) { } }
public <T, L extends Loader<T>> L init(int id, RetainState.OnCreate<L> create, Loader.Callbacks<T> callbacks) { @SuppressWarnings("unchecked") L loader = (L) loaders.get(id); if (loader == null) { loader = create.onCreate(); loaders.put(id, loader); } if (loader.isAttached()) { throw new IllegalStateException("Loader " + loader + " already has callbacks. Make sure you are using unique ids and that you are calling either detach() or destroy() when the Activity is destroyed."); } loader.setCallbacks(callbacks); return loader; }
LoaderManager { public <T, L extends Loader<T>> L init(int id, RetainState.OnCreate<L> create, Loader.Callbacks<T> callbacks) { @SuppressWarnings("unchecked") L loader = (L) loaders.get(id); if (loader == null) { loader = create.onCreate(); loaders.put(id, loader); } if (loader.isAttached()) { throw new IllegalStateException("Loader " + loader + " already has callbacks. Make sure you are using unique ids and that you are calling either detach() or destroy() when the Activity is destroyed."); } loader.setCallbacks(callbacks); return loader; } }
LoaderManager { public <T, L extends Loader<T>> L init(int id, RetainState.OnCreate<L> create, Loader.Callbacks<T> callbacks) { @SuppressWarnings("unchecked") L loader = (L) loaders.get(id); if (loader == null) { loader = create.onCreate(); loaders.put(id, loader); } if (loader.isAttached()) { throw new IllegalStateException("Loader " + loader + " already has callbacks. Make sure you are using unique ids and that you are calling either detach() or destroy() when the Activity is destroyed."); } loader.setCallbacks(callbacks); return loader; }  }
LoaderManager { public <T, L extends Loader<T>> L init(int id, RetainState.OnCreate<L> create, Loader.Callbacks<T> callbacks) { @SuppressWarnings("unchecked") L loader = (L) loaders.get(id); if (loader == null) { loader = create.onCreate(); loaders.put(id, loader); } if (loader.isAttached()) { throw new IllegalStateException("Loader " + loader + " already has callbacks. Make sure you are using unique ids and that you are calling either detach() or destroy() when the Activity is destroyed."); } loader.setCallbacks(callbacks); return loader; }  L init(int id, RetainState.OnCreate<L> create, Loader.Callbacks<T> callbacks); void remove(int id); void detach(); void destroy(); void onDestroy(RetainState retainState); }
LoaderManager { public <T, L extends Loader<T>> L init(int id, RetainState.OnCreate<L> create, Loader.Callbacks<T> callbacks) { @SuppressWarnings("unchecked") L loader = (L) loaders.get(id); if (loader == null) { loader = create.onCreate(); loaders.put(id, loader); } if (loader.isAttached()) { throw new IllegalStateException("Loader " + loader + " already has callbacks. Make sure you are using unique ids and that you are calling either detach() or destroy() when the Activity is destroyed."); } loader.setCallbacks(callbacks); return loader; }  L init(int id, RetainState.OnCreate<L> create, Loader.Callbacks<T> callbacks); void remove(int id); void detach(); void destroy(); void onDestroy(RetainState retainState); static final RetainState.OnCreate<LoaderManager> CREATE; }