Fix SocialWidgetConfigureActivity contact-picker double-launch.

No longer does SocialWidgetConfigureActivity launch a second
contact-picker when the picker result is returns in a different
device orientation.

Bug: 6478425
Change-Id: I51c6e91afb269f07bf45fb29aa017a0044baa237
diff --git a/src/com/android/contacts/socialwidget/SocialWidgetConfigureActivity.java b/src/com/android/contacts/socialwidget/SocialWidgetConfigureActivity.java
index 98812d9..39307bf 100644
--- a/src/com/android/contacts/socialwidget/SocialWidgetConfigureActivity.java
+++ b/src/com/android/contacts/socialwidget/SocialWidgetConfigureActivity.java
@@ -23,12 +23,19 @@
 import android.provider.ContactsContract.Contacts;
 
 public class SocialWidgetConfigureActivity extends Activity {
+    private static final String KEY_LAUNCHED = "already_launched_picker_activity";
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         // If the user presses back, we want to cancel
         setResult(RESULT_CANCELED);
 
+        // Don't launch contact-picker if we already launched it (for example, if
+        // we launched it in a previous onCreate() and the device orientation changes
+        // before the picker returns its result, then this activity will be recreated).
+        if (savedInstanceState != null && savedInstanceState.getBoolean(KEY_LAUNCHED)) return;
+
         // Forward the Intent to the picker
         final Intent pickerIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
         pickerIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
@@ -36,6 +43,14 @@
     }
 
     @Override
+    protected void onSaveInstanceState(Bundle savedInstanceState) {
+        super.onSaveInstanceState(savedInstanceState);
+
+        // We know for sure that we've launched the contact-picker... see onCreate()
+        savedInstanceState.putBoolean(KEY_LAUNCHED, true);
+    }
+
+    @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         // We came back from the Picker. If the user actually selected a contact,
         // return it now