private void setFriendPickerListeners(final FriendPickerFragment fragment) {
   fragment.setOnDoneButtonClickedListener(
       new FriendPickerFragment.OnDoneButtonClickedListener() {
         public void onDoneButtonClicked(PickerFragment<?> pickerFragment) {
           onFriendPickerDone(fragment);
         }
       });
 }
 private void finishActivity() {
   ScrumptiousApplication app = (ScrumptiousApplication) getApplication();
   if (FRIEND_PICKER.equals(getIntent().getData())) {
     if (friendPickerFragment != null) {
       app.setSelectedUsers(friendPickerFragment.getSelection());
     }
   } else if (PLACE_PICKER.equals(getIntent().getData())) {
     if (placePickerFragment != null) {
       app.setSelectedPlace(placePickerFragment.getSelection());
     }
   }
   setResult(RESULT_OK, null);
   finish();
 }
  private void onFriendPickerDone(FriendPickerFragment fragment) {
    FragmentManager fm = getSupportFragmentManager();
    fm.popBackStack();

    String results = "";

    Collection<GraphUser> selection = fragment.getSelection();
    if (selection != null && selection.size() > 0) {
      ArrayList<String> names = new ArrayList<String>();
      for (GraphUser user : selection) {
        names.add(user.getName());
      }
      results = TextUtils.join(", ", names);
    } else {
      results = "no friends";
    }

    showAlert("rar", results);
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pickers);

    Bundle args = getIntent().getExtras();
    FragmentManager manager = getSupportFragmentManager();
    Fragment fragmentToShow = null;
    Uri intentUri = getIntent().getData();

    if (FRIEND_PICKER.equals(intentUri)) {
      if (savedInstanceState == null) {
        friendPickerFragment = new FriendPickerFragment(args);
      } else {
        friendPickerFragment =
            (FriendPickerFragment) manager.findFragmentById(R.id.picker_fragment);
        ;
      }

      friendPickerFragment.setOnErrorListener(
          new PickerFragment.OnErrorListener() {
            @Override
            public void onError(FacebookException error) {
              PickerActivity.this.onError(error);
            }
          });
      friendPickerFragment.setOnDoneButtonClickedListener(
          new PickerFragment.OnDoneButtonClickedListener() {
            @Override
            public void onDoneButtonClicked() {
              finishActivity();
            }
          });
      fragmentToShow = friendPickerFragment;

    } else if (PLACE_PICKER.equals(intentUri)) {
      if (savedInstanceState == null) {
        placePickerFragment = new PlacePickerFragment(args);
      } else {
        placePickerFragment = (PlacePickerFragment) manager.findFragmentById(R.id.picker_fragment);
      }
      placePickerFragment.setOnSelectionChangedListener(
          new PickerFragment.OnSelectionChangedListener() {
            @Override
            public void onSelectionChanged() {
              finishActivity(); // call finish since you can only pick one place
            }
          });
      placePickerFragment.setOnErrorListener(
          new PickerFragment.OnErrorListener() {
            @Override
            public void onError(FacebookException error) {
              PickerActivity.this.onError(error);
            }
          });
      placePickerFragment.setOnDoneButtonClickedListener(
          new PickerFragment.OnDoneButtonClickedListener() {
            @Override
            public void onDoneButtonClicked() {
              finishActivity();
            }
          });
      fragmentToShow = placePickerFragment;
    } else {
      // Nothing to do, finish
      setResult(RESULT_CANCELED);
      finish();
      return;
    }

    manager.beginTransaction().replace(R.id.picker_fragment, fragmentToShow).commit();
  }
  @Override
  protected void onStart() {
    super.onStart();
    if (FRIEND_PICKER.equals(getIntent().getData())) {
      try {
        friendPickerFragment.loadData(false);
      } catch (Exception ex) {
        onError(ex);
      }
    } else if (PLACE_PICKER.equals(getIntent().getData())) {
      try {
        Location location = null;
        Criteria criteria = new Criteria();
        LocationManager locationManager =
            (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        String bestProvider = locationManager.getBestProvider(criteria, false);
        if (bestProvider != null) {
          location = locationManager.getLastKnownLocation(bestProvider);
          if (locationManager.isProviderEnabled(bestProvider) && locationListener == null) {
            locationListener =
                new LocationListener() {
                  @Override
                  public void onLocationChanged(Location location) {
                    float distance = location.distanceTo(placePickerFragment.getLocation());
                    if (distance >= LOCATION_CHANGE_THRESHOLD) {
                      placePickerFragment.setLocation(location);
                      placePickerFragment.loadData(true);
                    }
                  }

                  @Override
                  public void onStatusChanged(String s, int i, Bundle bundle) {}

                  @Override
                  public void onProviderEnabled(String s) {}

                  @Override
                  public void onProviderDisabled(String s) {}
                };
            locationManager.requestLocationUpdates(
                bestProvider,
                1,
                LOCATION_CHANGE_THRESHOLD,
                locationListener,
                Looper.getMainLooper());
          }
        }
        if (location == null) {
          String model = Build.MODEL;
          if (model.equals("sdk") || model.equals("google_sdk") || model.contains("x86")) {
            // this may be the emulator, pretend we're in an exotic place
            location = SAN_FRANCISCO_LOCATION;
          }
        }
        if (location != null) {
          placePickerFragment.setLocation(location);
          placePickerFragment.setRadiusInMeters(SEARCH_RADIUS_METERS);
          placePickerFragment.setSearchText(SEARCH_TEXT);
          placePickerFragment.setResultsLimit(SEARCH_RESULT_LIMIT);
          placePickerFragment.loadData(true);
        } else {
          onError(getResources().getString(R.string.no_location_error), true);
        }
      } catch (Exception ex) {
        onError(ex);
      }
    }
  }