am 89e68d78: Merge "Create main activity intents as needed for TaskStackBuilder/Up nav" into jb-mr1-dev
* commit '89e68d783b381a7dcbce5b1d603f4e2d8ee51c79': Create main activity intents as needed for TaskStackBuilder/Up nav
This commit is contained in:
@@ -5010,7 +5010,21 @@ public class Activity extends ContextThemeWrapper
|
|||||||
if (TextUtils.isEmpty(parentName)) {
|
if (TextUtils.isEmpty(parentName)) {
|
||||||
return null;
|
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 ------------------
|
// ------------------ Internal API ------------------
|
||||||
|
|||||||
@@ -124,24 +124,12 @@ public class TaskStackBuilder {
|
|||||||
* @return This TaskStackBuilder for method chaining
|
* @return This TaskStackBuilder for method chaining
|
||||||
*/
|
*/
|
||||||
public TaskStackBuilder addParentStack(Activity sourceActivity) {
|
public TaskStackBuilder addParentStack(Activity sourceActivity) {
|
||||||
final int insertAt = mIntents.size();
|
final Intent parent = sourceActivity.getParentActivityIntent();
|
||||||
Intent parent = sourceActivity.getParentActivityIntent();
|
if (parent != null) {
|
||||||
PackageManager pm = sourceActivity.getPackageManager();
|
// We have the actual parent intent, build the rest from static metadata
|
||||||
while (parent != null) {
|
// then add the direct parent intent to the end.
|
||||||
mIntents.add(insertAt, parent);
|
addParentStack(parent.getComponent());
|
||||||
try {
|
addNextIntent(parent);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -155,24 +143,7 @@ public class TaskStackBuilder {
|
|||||||
* @return This TaskStackBuilder for method chaining
|
* @return This TaskStackBuilder for method chaining
|
||||||
*/
|
*/
|
||||||
public TaskStackBuilder addParentStack(Class<?> sourceActivityClass) {
|
public TaskStackBuilder addParentStack(Class<?> sourceActivityClass) {
|
||||||
final int insertAt = mIntents.size();
|
return addParentStack(new ComponentName(mSourceContext, sourceActivityClass));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -191,11 +162,13 @@ public class TaskStackBuilder {
|
|||||||
ActivityInfo info = pm.getActivityInfo(sourceActivityName, 0);
|
ActivityInfo info = pm.getActivityInfo(sourceActivityName, 0);
|
||||||
String parentActivity = info.parentActivityName;
|
String parentActivity = info.parentActivityName;
|
||||||
while (parentActivity != null) {
|
while (parentActivity != null) {
|
||||||
Intent parent = new Intent().setComponent(
|
final ComponentName target = new ComponentName(mSourceContext, parentActivity);
|
||||||
new ComponentName(info.packageName, parentActivity));
|
info = pm.getActivityInfo(target, 0);
|
||||||
mIntents.add(insertAt, parent);
|
|
||||||
info = pm.getActivityInfo(parent.getComponent(), 0);
|
|
||||||
parentActivity = info.parentActivityName;
|
parentActivity = info.parentActivityName;
|
||||||
|
final Intent parent = parentActivity == null && insertAt == 0
|
||||||
|
? Intent.makeMainActivity(target)
|
||||||
|
: new Intent().setComponent(target);
|
||||||
|
mIntents.add(insertAt, parent);
|
||||||
}
|
}
|
||||||
} catch (NameNotFoundException e) {
|
} catch (NameNotFoundException e) {
|
||||||
Log.e(TAG, "Bad ComponentName while traversing activity parent metadata");
|
Log.e(TAG, "Bad ComponentName while traversing activity parent metadata");
|
||||||
|
|||||||
Reference in New Issue
Block a user