@Override
 public void onBackPressed() {
   if (mInSearchUi) {
     // We should let the user go back to usual screens with tabs.
     exitSearchUi();
   } else if (isTaskRoot()) {
     // Instead of stopping, simply push this to the back of the stack.
     // This is only done when running at the top of the stack;
     // otherwise, we have been launched by someone else so need to
     // allow the user to go back to the caller.
     moveTaskToBack(false);
   } else {
     super.onBackPressed();
   }
 }
  @Override
  public void onStart() {
    super.onStart();
    if (mPhoneFavoriteFragment != null) {
      mPhoneFavoriteFragment.setFilter(mContactListFilterController.getFilter());
    }
    if (mSearchFragment != null) {
      mSearchFragment.setFilter(mContactListFilterController.getFilter());
    }

    if (mDuringSwipe || mUserTabClick) {
      if (DEBUG) Log.d(TAG, "reset buggy flag state..");
      mDuringSwipe = false;
      mUserTabClick = false;
    }
  }
 @Override
 public void startSearch(
     String initialQuery, boolean selectInitialQuery, Bundle appSearchData, boolean globalSearch) {
   if (mSearchFragment != null && mSearchFragment.isAdded() && !globalSearch) {
     if (mInSearchUi) {
       if (mSearchView.hasFocus()) {
         showInputMethod(mSearchView.findFocus());
       } else {
         mSearchView.requestFocus();
       }
     } else {
       enterSearchUi();
     }
   } else {
     super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch);
   }
 }
  @Override
  protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    final Intent intent = getIntent();
    fixIntent(intent);

    setContentView(R.layout.dialtacts_activity);

    mContactListFilterController = ContactListFilterController.getInstance(this);
    mContactListFilterController.addListener(mContactListFilterListener);

    findViewById(R.id.dialtacts_frame).addOnLayoutChangeListener(mFirstLayoutListener);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(new ViewPagerAdapter(getFragmentManager()));
    mViewPager.setOnPageChangeListener(mPageChangeListener);

    // Setup the ActionBar tabs (the order matches the tab-index contants TAB_INDEX_*)
    setupDialer();
    setupCallLog();
    setupFavorites();
    getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    getActionBar().setDisplayShowTitleEnabled(false);
    getActionBar().setDisplayShowHomeEnabled(false);

    // Load the last manually loaded tab
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    mLastManuallySelectedFragment =
        mPrefs.getInt(PREF_LAST_MANUALLY_SELECTED_TAB, PREF_LAST_MANUALLY_SELECTED_TAB_DEFAULT);
    if (mLastManuallySelectedFragment >= TAB_INDEX_COUNT) {
      // Stored value may have exceeded the number of current tabs. Reset it.
      mLastManuallySelectedFragment = PREF_LAST_MANUALLY_SELECTED_TAB_DEFAULT;
    }

    setCurrentTab(intent);

    if (UI.FILTER_CONTACTS_ACTION.equals(intent.getAction()) && icicle == null) {
      setupFilterText(intent);
    }
  }
  @Override
  protected void onPause() {
    super.onPause();

    mPrefs.edit().putInt(PREF_LAST_MANUALLY_SELECTED_TAB, mLastManuallySelectedFragment).apply();
  }
 @Override
 public void onDestroy() {
   super.onDestroy();
   mContactListFilterController.removeListener(mContactListFilterListener);
 }