Merge "Fix IllegalStateException in start" into ub-contactsdialer-a-dev
diff --git a/src/com/android/contacts/activities/ContactSelectionActivity.java b/src/com/android/contacts/activities/ContactSelectionActivity.java
index 36e805c..53bfce0 100644
--- a/src/com/android/contacts/activities/ContactSelectionActivity.java
+++ b/src/com/android/contacts/activities/ContactSelectionActivity.java
@@ -84,6 +84,8 @@
     private ContactsIntentResolver mIntentResolver;
     protected ContactEntryListFragment<?> mListFragment;
 
+    private boolean mIsVisible;
+
     private int mActionCode = -1;
     private boolean mIsSearchMode;
     private boolean mIsSearchSupported;
@@ -137,6 +139,25 @@
         prepareSearchViewAndActionBar();
     }
 
+    @Override
+    protected void onStart() {
+        super.onStart();
+        mIsVisible = true;
+    }
+
+    @Override
+    protected void onStop() {
+        mIsVisible = false;
+        super.onStop();
+    }
+
+    /**
+     * Returns true when the Activity is currently visible (between onStart and onStop).
+     */
+    /* package */ boolean isVisible() {
+        return mIsVisible;
+    }
+
     private void prepareSearchViewAndActionBar() {
         final ActionBar actionBar = getActionBar();
         mSearchViewContainer = LayoutInflater.from(actionBar.getThemedContext())
@@ -212,6 +233,7 @@
 
     @Override
     protected void onSaveInstanceState(Bundle outState) {
+        mIsVisible = false;
         super.onSaveInstanceState(outState);
         outState.putInt(KEY_ACTION_CODE, mActionCode);
         outState.putBoolean(KEY_SEARCH_MODE, mIsSearchMode);
@@ -484,17 +506,13 @@
     private final class PhoneNumberPickerActionListener implements
             OnPhoneNumberPickerActionListener {
         @Override
-        public void onPickPhoneNumberAction(Uri dataUri) {
+        public void onPickPhoneNumberAction(Uri dataUri, int callInitiationType) {
             returnPickerResult(dataUri);
         }
 
         @Override
-        public void onCallNumberDirectly(String phoneNumber) {
-            Log.w(TAG, "Unsupported call.");
-        }
-
-        @Override
-        public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
+        public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall,
+                int callInitiationType) {
             Log.w(TAG, "Unsupported call.");
         }
 
@@ -503,6 +521,7 @@
             returnPickerResult(intent);
         }
 
+        @Override
         public void onHomeInActionBarSelected() {
             ContactSelectionActivity.this.onBackPressed();
         }
@@ -672,6 +691,10 @@
 
     @Override
     public void onBackPressed() {
+        if (!isVisible()) {
+            return;
+        }
+
         if (mIsSearchMode) {
             mIsSearchMode = false;
             configureSearchMode();