summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAdam Powell <adamp@google.com>2012-09-16 15:14:05 -0700
committerAdam Powell <adamp@google.com>2012-09-16 15:15:46 -0700
commit5a4010c054a4449156df885ad0f46f8db3263d87 (patch)
tree9ab87360254ccb140cfc0dc6dd3ecf9fca665323 /core
parent306df86302a96c7bf3d86aed81190c10ea6c2ccd (diff)
downloadframeworks_base-5a4010c054a4449156df885ad0f46f8db3263d87.zip
frameworks_base-5a4010c054a4449156df885ad0f46f8db3263d87.tar.gz
frameworks_base-5a4010c054a4449156df885ad0f46f8db3263d87.tar.bz2
Create main activity intents as needed for TaskStackBuilder/Up nav
If a generated parent intent targets an Activity that itself has no parent specified, generate the intent using Intent.makeMainActivity to gather the correct flags for the root intent of a task. Bug 6457058 Change-Id: I8d4a3823eda752306da18c2c38fa7e57f0a33bf3
Diffstat (limited to 'core')
-rw-r--r--core/java/android/app/Activity.java16
-rw-r--r--core/java/android/app/TaskStackBuilder.java53
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");