android-arch-sample
android-arch-sample copied to clipboard
Removing Android framework dependency in the `PresenterManager` class
The PresenterManager
class currently accepts a Bundle
object passed via the savePresenter(BasePresenter<?, ?> presenter, Bundle outState)
and the restorePresenter(Bundle savedInstanceState)
to keep a reference of a presenter. This makes a dependency on the Android framework.
What about passing a unique key string from the Activity
(or Fragment
) that uses this presenter? This will remove the dependency on the Bundle
class as well.
For example,
-
savePresenter(BasePresenter<?, ?> presenter, String key)
-
restorePresenter(String key)
and in Activity
's onCreate()
method,
private static final String MY_ACTIVITY_KEY = "login_activity";
.....
if (savedInstanceState == null) {
presenter = new MainPresenter();
} else {
presenter = PresenterManager.getInstance().restorePresenter(MY_ACTIVITY_KEY);
}