diff --git a/app/src/main/java/mobi/maptrek/MapTrek.java b/app/src/main/java/mobi/maptrek/MapTrek.java index 0556dde5..7be93859 100644 --- a/app/src/main/java/mobi/maptrek/MapTrek.java +++ b/app/src/main/java/mobi/maptrek/MapTrek.java @@ -515,7 +515,8 @@ synchronized public void optionallyCloseMapDatabase(UUID id) { } } - public void onMainActivityFinishing() { + public void onMainActivityFinished() { + logger.info("MainActivity finished"); optionallyCloseMapDatabase(null); if (mWaypointDbDataSource != null) { mWaypointDbDataSource.close(); @@ -630,7 +631,6 @@ public void uncaughtException(@NonNull final Thread thread, @NonNull final Throw } class ListeningToActivityCallbacks implements Application.ActivityLifecycleCallbacks { - @Override public void onActivityCreated(@NonNull Activity activity, Bundle savedInstanceState) { logger.warn("{} is onActivityCreated", activity.getLocalClassName()); @@ -666,10 +666,14 @@ public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bun @Override public void onActivityDestroyed(@NonNull Activity activity) { logger.warn("{} is onActivityDestroyed", activity.getLocalClassName()); - if (activity.isFinishing() && activity.getLocalClassName().equals(MainActivity.class.getSimpleName())) { + if (activity.isFinishing() && activity.getLocalClassName().equals(MainActivity.class.getSimpleName())) mMainActivityExists = false; - onMainActivityFinishing(); - } + } + + @Override + public void onActivityPostDestroyed(@NonNull Activity activity) { + if (!mMainActivityExists && activity.getLocalClassName().equals(MainActivity.class.getSimpleName())) + onMainActivityFinished(); } } }