android-arch-sample icon indicating copy to clipboard operation
android-arch-sample copied to clipboard

Null presenter

Open rackaam opened this issue 8 years ago • 0 comments

Hi,

In this code (from https://github.com/remind101/android-arch-sample/blob/master/app/src/main/java/com/remind101/archexample/MainActivity.java), the saved instance state may be not null (back navigation), and PresenterManager.getInstance().restorePresenter() may return null (the cache use an expirationValue). In this case, after this code, the presenter is null and the app will certainly crash.

if (savedInstanceState == null) {
      presenter = new MainPresenter();
} else {
      presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
}

Should the code not be more something like this or am I missing something?

if (savedInstanceState != null) {
      presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
}
if (presenter == null) {
      presenter = new MainPresenter();
}

rackaam avatar May 27 '16 15:05 rackaam