From 6730171634cc41a4ea46cb8bfc91b4d822ae4a0c Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sat, 21 Feb 2015 18:13:45 +0100 Subject: fix up navigation once more --- main/res/values/changelog_master.xml | 1 + main/src/cgeo/geocaching/activity/ActivityMixin.java | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'main') diff --git a/main/res/values/changelog_master.xml b/main/res/values/changelog_master.xml index 015c70b..4cb262d 100644 --- a/main/res/values/changelog_master.xml +++ b/main/res/values/changelog_master.xml @@ -24,6 +24,7 @@ · Fix: Do not limit to 10 logs for OC caches\n · Fix: Recognize more hyperlinks of opencaching caches\n · Fix: Remove empty space in some opencaching logs\n + · Fix: Allow up navigation when opening the app from a link\n \n diff --git a/main/src/cgeo/geocaching/activity/ActivityMixin.java b/main/src/cgeo/geocaching/activity/ActivityMixin.java index e9d3249..5b3be70 100644 --- a/main/src/cgeo/geocaching/activity/ActivityMixin.java +++ b/main/src/cgeo/geocaching/activity/ActivityMixin.java @@ -1,5 +1,7 @@ package cgeo.geocaching.activity; +import cgeo.geocaching.CgeoApplication; +import cgeo.geocaching.MainActivity; import cgeo.geocaching.R; import cgeo.geocaching.settings.Settings; @@ -155,20 +157,18 @@ public final class ActivityMixin { editText.setSelection(newCursor); } - /** - * This is the exact code from Google to implement Up navigation, with one exception: activity.isTaskRoot() was - * added as {@link NavUtils#shouldUpRecreateTask(Activity, Intent)} seems not to handle the case, that this activity - * was created from an intent by another app, and our own app is not yet running. The bug seems to be fixed in - * Android 4.4.something, however. - * - */ public static boolean navigateUp(@NonNull final Activity activity) { - // see http://developer.android.com/training/implementing-navigation/ancestral.html - final Intent upIntent = NavUtils.getParentActivityIntent(activity); - if (upIntent == null) { + // first check if there is a parent declared in the manifest + Intent upIntent = NavUtils.getParentActivityIntent(activity); + // if there is no parent, and if this was not a new task, then just go back to simulate going to a parent + if (upIntent == null && !activity.isTaskRoot()) { activity.finish(); return true; } + // use the main activity, if there was no back stack and no manifest based parent + if (upIntent == null) { + upIntent = new Intent(CgeoApplication.getInstance(), MainActivity.class); + } if (NavUtils.shouldUpRecreateTask(activity, upIntent) || activity.isTaskRoot()) { // This activity is NOT part of this app's task, so create a new task // when navigating up, with a synthesized back stack. -- cgit v1.1