@Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.refreshOption) {
      getAllMessages();
      return true;
    } else if (id == R.id.compose_message) {
      Intent intent = new Intent(MessagesActivity.this, ComposeActivity.class);
      startActivity(intent);
      return true;
    } else if (id == R.id.logoutOption) {
      ParseUser.logOutInBackground(
          new LogOutCallback() {
            @Override
            public void done(ParseException e) {
              finish();
              Intent intent = new Intent(MessagesActivity.this, MainActivity.class);
              startActivity(intent);
            }
          });
    }

    return super.onOptionsItemSelected(item);
  }
  @Override
  public void onSnackListUpdateComplete(ParseException e) {
    // Start the login activity if the session token is invalid.
    if (e != null && e.getCode() == ParseException.INVALID_SESSION_TOKEN) {
      if (myActivity != null) {
        Intent startLoginIntent = new Intent(myActivity, LoginActivity.class);
        ParseUser.logOutInBackground();
        myActivity.finish();
        startActivity(startLoginIntent);
      }
    }

    adapter.notifyDataSetChanged();

    if (progressOverlay != null) {
      progressOverlay.setVisibility(View.GONE);
    }

    // Show the help message if appropriate.
    // That is, if we haven't already showed it for the current user this session and the
    // current user has zero entries. Only show the help message if the SnackList is pointing
    // at the current user.
    if (lastShowedHelpFor != ParseUser.getCurrentUser()
        && !showingHelp
        && SnackList.getInstance().size() == 0
        && ParseUser.getCurrentUser().equals(SnackList.getInstance().getUser())) {
      try {
        showHelpMessage();
      } catch (IllegalStateException ignored) {
        // In the case that onSaveInstanceState has been already been called, we ignore
        // the exception.
      }
    }
  }
 public void logout(final OnParseUserLogoutListener listener) {
   ParseUser.logOutInBackground(
       new LogOutCallback() {
         @Override
         public void done(ParseException e) {
           Master.unpinAll();
           Permission.unpinAll();
           Slave.unpinAll();
           listener.userLoggedOut();
         }
       });
 }