Fix crash in QC during orientation change

 - Also made the ContactLoader a little more robust. The cached result
   is now a new instance so that it is recognized by the LoaderManager
   as new data

Bug:6356584

Change-Id: I4e2eca92501308a8724b00771038555fa59b3260
diff --git a/src/com/android/contacts/ContactLoader.java b/src/com/android/contacts/ContactLoader.java
index c0399e4..5f5c1cb 100644
--- a/src/com/android/contacts/ContactLoader.java
+++ b/src/com/android/contacts/ContactLoader.java
@@ -1297,6 +1297,9 @@
      * new result will be delivered
      */
     public void upgradeToFullContact() {
+        // Everything requested already? Nothing to do, so let's bail out
+        if (mLoadGroupMetaData && mLoadInvitableAccountTypes && mLoadStreamItems) return;
+
         mLoadGroupMetaData = true;
         mLoadInvitableAccountTypes = true;
         mLoadStreamItems = true;
@@ -1346,6 +1349,6 @@
      * contact. If the next load is for a different contact, the cached result will be dropped
      */
     public void cacheResult() {
-        sCachedResult = mContact;
+        sCachedResult = new Result(mContact);
     }
 }
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index 7087167..11f3da1 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -31,7 +31,6 @@
 import android.app.Fragment;
 import android.app.FragmentManager;
 import android.app.LoaderManager.LoaderCallbacks;
-import android.app.TaskStackBuilder;
 import android.content.ActivityNotFoundException;
 import android.content.ContentUris;
 import android.content.ContentValues;
@@ -225,7 +224,8 @@
         mPhotoContainer = findViewById(R.id.photo_container);
         setHeaderNameText(R.id.name, R.string.missing_name);
 
-        getLoaderManager().initLoader(LOADER_ID, null, mLoaderCallbacks);
+        mContactLoader = (ContactLoader) getLoaderManager().initLoader(
+                LOADER_ID, null, mLoaderCallbacks);
     }
 
     private boolean handleOutsideTouch() {
@@ -523,8 +523,7 @@
             if (mLookupUri == null) {
                 Log.wtf(TAG, "Lookup uri wasn't initialized. Loader was started too early");
             }
-            mContactLoader = new ContactLoader(getApplicationContext(), mLookupUri);
-            return mContactLoader;
+            return new ContactLoader(getApplicationContext(), mLookupUri);
         }
     };