@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    registerReceiver(mLoggedOutReceiver, new IntentFilter(Foursquared.INTENT_ACTION_LOGGED_OUT));

    Object retained = getLastNonConfigurationInstance();
    if (retained != null && retained instanceof StateHolder) {
      mStateHolder = (StateHolder) retained;
      mStateHolder.setActivity(this);
    } else {
      if (getIntent().hasExtra(INTENT_EXTRA_USER_ID)
          && getIntent().hasExtra(INTENT_EXTRA_USER_NAME)) {
        mStateHolder =
            new StateHolder(
                getIntent().getStringExtra(INTENT_EXTRA_USER_ID),
                getIntent().getStringExtra(INTENT_EXTRA_USER_NAME));
        mStateHolder.setRecentOnly(true);
      } else {
        Log.e(TAG, TAG + " requires user ID and name in intent extras.");
        finish();
        return;
      }
    }

    ensureUi();

    // Friend tips is shown first by default so auto-fetch it if necessary.
    if (!mStateHolder.getRanOnceTipsRecent()) {
      mStateHolder.startTaskTips(this, true);
    }
  }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    menu.add(Menu.NONE, MENU_REFRESH, Menu.NONE, R.string.refresh)
        .setIcon(R.drawable.ic_menu_refresh);

    return true;
  }
  @Override
  public void onPause() {
    super.onPause();

    ((Foursquared) getApplication()).removeLocationUpdates(mSearchLocationObserver);

    if (isFinishing()) {
      mStateHolder.cancelTasks();
      mListAdapter.removeObserver();
      unregisterReceiver(mLoggedOutReceiver);
    }
  }
  @Override
  public void onResume() {
    super.onResume();

    ((Foursquared) getApplication()).requestLocationUpdates(mSearchLocationObserver);
  }