summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Powell <adamp@google.com>2012-04-09 10:22:12 -0700
committerAdam Powell <adamp@google.com>2012-04-09 10:31:15 -0700
commit04d5811500874d44010df2b4ce37a0b21095168f (patch)
tree351bac0ba6a305a65bc3d0a38cc55e0a9aa1f2b0
parente2427cac775390ecae2cd6d0d2ab2a3d6280f2df (diff)
downloadframeworks_base-04d5811500874d44010df2b4ce37a0b21095168f.zip
frameworks_base-04d5811500874d44010df2b4ce37a0b21095168f.tar.gz
frameworks_base-04d5811500874d44010df2b4ce37a0b21095168f.tar.bz2
Tweaks to Activity up navigation
Be more explicit in docs about getParentActivityIntent and guard against calls when a parent has not been declared in the manifest. Move automatic up navigation to happen after dispatch of the menu selection event of id android.R.id.home to fragments. (Last.) Fixes bug 6305357 Change-Id: I944e5c40774121f9a28250d8d98da6aa646f9357
-rw-r--r--core/java/android/app/Activity.java35
1 files changed, 23 insertions, 12 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index 3e123ba..7207e29 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -2522,7 +2522,19 @@ public class Activity extends ContextThemeWrapper
if (onOptionsItemSelected(item)) {
return true;
}
- return mFragments.dispatchOptionsItemSelected(item);
+ if (mFragments.dispatchOptionsItemSelected(item)) {
+ return true;
+ }
+ if (item.getItemId() == android.R.id.home && mActionBar != null &&
+ (mActionBar.getDisplayOptions() & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
+ if (mParent == null) {
+ onNavigateUp();
+ } else {
+ mParent.onNavigateUpFromChild(this);
+ }
+ return true;
+ }
+ return false;
case Window.FEATURE_CONTEXT_MENU:
EventLog.writeEvent(50000, 1, item.getTitleCondensed());
@@ -2654,15 +2666,6 @@ public class Activity extends ContextThemeWrapper
if (mParent != null) {
return mParent.onOptionsItemSelected(item);
}
- if (item.getItemId() == android.R.id.home && mActionBar != null &&
- (mActionBar.getDisplayOptions() & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
- if (mParent == null) {
- onNavigateUp();
- } else {
- mParent.onNavigateUpFromChild(this);
- }
- return true;
- }
return false;
}
@@ -4865,11 +4868,19 @@ public class Activity extends ContextThemeWrapper
* Obtain an {@link Intent} that will launch an explicit target activity specified by
* this activity's logical parent. The logical parent is named in the application's manifest
* by the {@link android.R.attr#parentActivityName parentActivityName} attribute.
+ * Activity subclasses may override this method to modify the Intent returned by
+ * super.getParentActivityIntent() or to implement a different mechanism of retrieving
+ * the parent intent entirely.
*
- * @return a new Intent targeting the defined parent of this activity
+ * @return a new Intent targeting the defined parent of this activity or null if
+ * there is no valid parent.
*/
public Intent getParentActivityIntent() {
- return new Intent().setClassName(this, mActivityInfo.parentActivityName);
+ final String parentName = mActivityInfo.parentActivityName;
+ if (TextUtils.isEmpty(parentName)) {
+ return null;
+ }
+ return new Intent().setClassName(this, parentName);
}
// ------------------ Internal API ------------------