Skip to content

Commit 081cc9a

Browse files
adampAndroid (Google) Code Review
authored andcommitted
Merge "Tweaks to Activity up navigation"
2 parents 4b3c523 + 04d5811 commit 081cc9a

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

core/java/android/app/Activity.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,7 +2522,19 @@ public boolean onMenuItemSelected(int featureId, MenuItem item) {
25222522
if (onOptionsItemSelected(item)) {
25232523
return true;
25242524
}
2525-
return mFragments.dispatchOptionsItemSelected(item);
2525+
if (mFragments.dispatchOptionsItemSelected(item)) {
2526+
return true;
2527+
}
2528+
if (item.getItemId() == android.R.id.home && mActionBar != null &&
2529+
(mActionBar.getDisplayOptions() & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
2530+
if (mParent == null) {
2531+
onNavigateUp();
2532+
} else {
2533+
mParent.onNavigateUpFromChild(this);
2534+
}
2535+
return true;
2536+
}
2537+
return false;
25262538

25272539
case Window.FEATURE_CONTEXT_MENU:
25282540
EventLog.writeEvent(50000, 1, item.getTitleCondensed());
@@ -2654,15 +2666,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
26542666
if (mParent != null) {
26552667
return mParent.onOptionsItemSelected(item);
26562668
}
2657-
if (item.getItemId() == android.R.id.home && mActionBar != null &&
2658-
(mActionBar.getDisplayOptions() & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
2659-
if (mParent == null) {
2660-
onNavigateUp();
2661-
} else {
2662-
mParent.onNavigateUpFromChild(this);
2663-
}
2664-
return true;
2665-
}
26662669
return false;
26672670
}
26682671

@@ -4865,11 +4868,19 @@ public boolean navigateUpToFromChild(Activity child, Intent upIntent) {
48654868
* Obtain an {@link Intent} that will launch an explicit target activity specified by
48664869
* this activity's logical parent. The logical parent is named in the application's manifest
48674870
* by the {@link android.R.attr#parentActivityName parentActivityName} attribute.
4871+
* Activity subclasses may override this method to modify the Intent returned by
4872+
* super.getParentActivityIntent() or to implement a different mechanism of retrieving
4873+
* the parent intent entirely.
48684874
*
4869-
* @return a new Intent targeting the defined parent of this activity
4875+
* @return a new Intent targeting the defined parent of this activity or null if
4876+
* there is no valid parent.
48704877
*/
48714878
public Intent getParentActivityIntent() {
4872-
return new Intent().setClassName(this, mActivityInfo.parentActivityName);
4879+
final String parentName = mActivityInfo.parentActivityName;
4880+
if (TextUtils.isEmpty(parentName)) {
4881+
return null;
4882+
}
4883+
return new Intent().setClassName(this, parentName);
48734884
}
48744885

48754886
// ------------------ Internal API ------------------

0 commit comments

Comments
 (0)