From 7f8a8aa5cbcab20dbdb53d688135a3c6828fd19d Mon Sep 17 00:00:00 2001 From: Christophe Beyls Date: Wed, 4 Feb 2015 23:30:13 +0100 Subject: [PATCH] Improve readability of up navigation code in EventDetailsActivity and add missing flags in the Manifest file for it. --- app/src/main/AndroidManifest.xml | 8 +++- .../activities/EventDetailsActivity.java | 37 +++++++++++-------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b1371c0..e6396f2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,16 @@ - + @@ -60,6 +63,9 @@ + , CreateNfcAppDataCallback { @@ -74,21 +73,27 @@ public class EventDetailsActivity extends ActionBarActivity implements LoaderCal @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { - case android.R.id.home: - // Navigate up to the track associated to this event - Intent upIntent = new Intent(this, TrackScheduleActivity.class); - upIntent.putExtra(TrackScheduleActivity.EXTRA_DAY, event.getDay()); - upIntent.putExtra(TrackScheduleActivity.EXTRA_TRACK, event.getTrack()); - upIntent.putExtra(TrackScheduleActivity.EXTRA_FROM_EVENT_ID, event.getId()); - upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + case android.R.id.home: + // Navigate up to the track associated with this event + Intent upIntent = new Intent(this, TrackScheduleActivity.class); + upIntent.putExtra(TrackScheduleActivity.EXTRA_DAY, event.getDay()); + upIntent.putExtra(TrackScheduleActivity.EXTRA_TRACK, event.getTrack()); + upIntent.putExtra(TrackScheduleActivity.EXTRA_FROM_EVENT_ID, event.getId()); - finish(); - if (NavUtils.shouldUpRecreateTask(this, upIntent)) { - TaskStackBuilder.create(this).addNextIntent(new Intent(this, MainActivity.class)).addNextIntent(upIntent).startActivities(); - } else { - startActivity(upIntent); - } - return true; + if (NavUtils.shouldUpRecreateTask(this, upIntent)) { + TaskStackBuilder.create(this) + .addNextIntentWithParentStack(upIntent) + .startActivities(); + finish(); + } else { + // Replicate the compatibility implementation of NavUtils.navigateUpTo() + // to ensure the parent Activity is always launched + // even if not present on the back stack. + upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(upIntent); + finish(); + } + return true; } return false; }