@Override
  public void onSaveInstanceState(Bundle outState) {

    Set<Long> toInvite = friendListAdapter.getSelectedList();
    Long inviteLongArray[] = toInvite.toArray(new Long[toInvite.size()]);

    Set<Long> alreadyGrouped = friendListAdapter.getAlreadyInGroupList();
    Long alreadyGroupedLongArray[] = alreadyGrouped.toArray(new Long[alreadyGrouped.size()]);

    outState.putParcelableArrayList(
        FRIEND_LIST_MODELS, new ArrayList<Parcelable>(friendListAdapter.getItems()));
    outState.putLongArray(FRIEND_LIST_STATES, JavaUtil.toPrimitive(inviteLongArray));
    outState.putLongArray(
        FRIEND_LIST_ALREADY_IN_GROUP, JavaUtil.toPrimitive(alreadyGroupedLongArray));

    super.onSaveInstanceState(outState);
  }
  @Override
  public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (savedInstanceState != null) {
      ArrayList<SocialMember> friends =
          savedInstanceState.getParcelableArrayList(FRIEND_LIST_MODELS);

      friendListAdapter.setItems(friends);

      // Restore the saved selected set
      long[] selected = savedInstanceState.getLongArray(FRIEND_LIST_STATES);
      if (selected != null) {
        friendListAdapter.setSelectedList(JavaUtil.primitiveLongToSet(selected));
      }
      // Restore the saved already in group set
      long[] alreadyInGroup = savedInstanceState.getLongArray(FRIEND_LIST_ALREADY_IN_GROUP);
      if (alreadyInGroup != null) {
        friendListAdapter.setAlreadyInGroupList(JavaUtil.primitiveLongToSet(alreadyInGroup));
      }
      refreshPage(State.LOADED);
    } else if (getArguments() != null && getArguments().containsKey(EXTRA_OPT_FRIENDS_LIST)) {
      List<SocialMember> friends = getArguments().getParcelableArrayList(EXTRA_OPT_FRIENDS_LIST);
      friendListAdapter.setItems(friends);
      refreshPage(State.LOADED);
    } else {
      friendProvider.getMyFriends(getActivity(), this);
      refreshPage(State.LOADING);
    }

    // Retrieve the already in group list
    if (getArguments() != null && getArguments().containsKey(EXTRA_OPT_IN_GROUP)) {

      long[] alreadyInGroup = getArguments().getLongArray(EXTRA_OPT_IN_GROUP);
      friendListAdapter.setAlreadyInGroupList(JavaUtil.primitiveLongToSet(alreadyInGroup));
    }
  }