diff options
author | Adam Powell <adamp@google.com> | 2012-09-16 15:46:58 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-09-16 15:46:58 -0700 |
commit | 89e68d783b381a7dcbce5b1d603f4e2d8ee51c79 (patch) | |
tree | a3d903e62b67f90da3f0859da2239d34563311de /core | |
parent | 3849490c6314d5887f534cc5dea0fc56499465aa (diff) | |
parent | 5a4010c054a4449156df885ad0f46f8db3263d87 (diff) | |
download | frameworks_base-89e68d783b381a7dcbce5b1d603f4e2d8ee51c79.zip frameworks_base-89e68d783b381a7dcbce5b1d603f4e2d8ee51c79.tar.gz frameworks_base-89e68d783b381a7dcbce5b1d603f4e2d8ee51c79.tar.bz2 |
Merge "Create main activity intents as needed for TaskStackBuilder/Up nav" into jb-mr1-dev
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/app/Activity.java | 16 | ||||
-rw-r--r-- | core/java/android/app/TaskStackBuilder.java | 53 |
2 files changed, 28 insertions, 41 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 05b04dc..7606d5e 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -5010,7 +5010,21 @@ public class Activity extends ContextThemeWrapper if (TextUtils.isEmpty(parentName)) { return null; } - return new Intent().setClassName(this, parentName); + + // If the parent itself has no parent, generate a main activity intent. + final ComponentName target = new ComponentName(this, parentName); + try { + final ActivityInfo parentInfo = getPackageManager().getActivityInfo(target, 0); + final String parentActivity = parentInfo.parentActivityName; + final Intent parentIntent = parentActivity == null + ? Intent.makeMainActivity(target) + : new Intent().setComponent(target); + return parentIntent; + } catch (NameNotFoundException e) { + Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName + + "' in manifest"); + return null; + } } // ------------------ Internal API ------------------ diff --git a/core/java/android/app/TaskStackBuilder.java b/core/java/android/app/TaskStackBuilder.java index f21b3fd..9c83362 100644 --- a/core/java/android/app/TaskStackBuilder.java +++ b/core/java/android/app/TaskStackBuilder.java @@ -124,24 +124,12 @@ public class TaskStackBuilder { * @return This TaskStackBuilder for method chaining */ public TaskStackBuilder addParentStack(Activity sourceActivity) { - final int insertAt = mIntents.size(); - Intent parent = sourceActivity.getParentActivityIntent(); - PackageManager pm = sourceActivity.getPackageManager(); - while (parent != null) { - mIntents.add(insertAt, parent); - try { - ActivityInfo info = pm.getActivityInfo(parent.getComponent(), 0); - String parentActivity = info.parentActivityName; - if (parentActivity != null) { - parent = new Intent().setComponent( - new ComponentName(mSourceContext, parentActivity)); - } else { - parent = null; - } - } catch (NameNotFoundException e) { - Log.e(TAG, "Bad ComponentName while traversing activity parent metadata"); - throw new IllegalArgumentException(e); - } + final Intent parent = sourceActivity.getParentActivityIntent(); + if (parent != null) { + // We have the actual parent intent, build the rest from static metadata + // then add the direct parent intent to the end. + addParentStack(parent.getComponent()); + addNextIntent(parent); } return this; } @@ -155,24 +143,7 @@ public class TaskStackBuilder { * @return This TaskStackBuilder for method chaining */ public TaskStackBuilder addParentStack(Class<?> sourceActivityClass) { - final int insertAt = mIntents.size(); - PackageManager pm = mSourceContext.getPackageManager(); - try { - ActivityInfo info = pm.getActivityInfo( - new ComponentName(mSourceContext, sourceActivityClass), 0); - String parentActivity = info.parentActivityName; - while (parentActivity != null) { - Intent parent = new Intent().setComponent( - new ComponentName(mSourceContext, parentActivity)); - mIntents.add(insertAt, parent); - info = pm.getActivityInfo(parent.getComponent(), 0); - parentActivity = info.parentActivityName; - } - } catch (NameNotFoundException e) { - Log.e(TAG, "Bad ComponentName while traversing activity parent metadata"); - throw new IllegalArgumentException(e); - } - return this; + return addParentStack(new ComponentName(mSourceContext, sourceActivityClass)); } /** @@ -191,11 +162,13 @@ public class TaskStackBuilder { ActivityInfo info = pm.getActivityInfo(sourceActivityName, 0); String parentActivity = info.parentActivityName; while (parentActivity != null) { - Intent parent = new Intent().setComponent( - new ComponentName(info.packageName, parentActivity)); - mIntents.add(insertAt, parent); - info = pm.getActivityInfo(parent.getComponent(), 0); + final ComponentName target = new ComponentName(mSourceContext, parentActivity); + info = pm.getActivityInfo(target, 0); parentActivity = info.parentActivityName; + final Intent parent = parentActivity == null && insertAt == 0 + ? Intent.makeMainActivity(target) + : new Intent().setComponent(target); + mIntents.add(insertAt, parent); } } catch (NameNotFoundException e) { Log.e(TAG, "Bad ComponentName while traversing activity parent metadata"); |