Merge "Fix issue #7178865: Selecting an app from Settings > Apps>..." into jb-mr1-dev
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index 907bf53..2284b91 100644
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -379,8 +379,6 @@
     @Override
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
-        
-        setHasOptionsMenu(true);
 
         mState = ApplicationsState.getInstance(getActivity().getApplication());
         mSession = mState.newSession(this);
@@ -393,6 +391,10 @@
         mSmsManager = ISms.Stub.asInterface(ServiceManager.getService("isms"));
 
         mCanBeOnSdCardChecker = new CanBeOnSdCardChecker();
+
+        retrieveAppEntry();
+
+        setHasOptionsMenu(true);
     }
 
     @Override
@@ -452,6 +454,8 @@
         boolean showIt = true;
         if (mUpdatedSysApp) {
             showIt = false;
+        } else if (mAppEntry == null) {
+            showIt = false;
         } else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
             showIt = false;
         } else if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
@@ -549,10 +553,7 @@
     public void onRunningStateChanged(boolean running) {
     }
 
-    private boolean refreshUi() {
-        if (mMoveInProgress) {
-            return true;
-        }
+    private String retrieveAppEntry() {
         final Bundle args = getArguments();
         String packageName = (args != null) ? args.getString(ARG_PACKAGE_NAME) : null;
         if (packageName == null) {
@@ -563,7 +564,15 @@
             }
         }
         mAppEntry = mState.getEntry(packageName);
-        
+        return packageName;
+    }
+
+    private boolean refreshUi() {
+        if (mMoveInProgress) {
+            return true;
+        }
+        final String packageName = retrieveAppEntry();
+
         if (mAppEntry == null) {
             return false; // onCreate must have failed, make sure to exit
         }