@Override
  protected void onCreate(Bundle savedInstanceState) {
    Log.e(TAG, "onCreate");
    super.onCreate(savedInstanceState);

    MyAppApplication myApp = ((MyAppApplication) getApplicationContext());
    mGoogleApiClient = myApp.getClient();
    room = myApp.getRoom();
    mRoomId = room.getRoomId();
    mParticipants = room.getParticipants();

    Intent i = getIntent();
    myself = (Player) i.getSerializableExtra("myself");

    AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
    initialize(new CatMath(this, myself), config); // updated by siyuan

    myId = room.getParticipantId(Games.Players.getCurrentPlayerId(myApp.getClient()));
    GameWorld.isOwner = isServer();
    Log.e("isOwner:", String.valueOf(GameWorld.isOwner));
    playerMap.put(myId, 1);
    GameWorld.numberOfPlayers = mParticipants.size();

    Log.e(TAG, "onCreate ends");
  } // end of onCreate
 public static void onSavedInstance(final Bundle outState, final Activity_Main main) {
   try {
     if (main.getGC().isConnected())
       outState.putString("player", Games.Players.getCurrentPlayer(main.getGC()).getDisplayName());
     else outState.remove("player");
   } catch (Exception e) {
     if (BuildConfig.DEBUG) Logger.log(e);
   }
 }
  public static void setupAccountSetting(
      final Preference account, final Bundle savedInstanceState, final Activity_Main main) {
    account.setOnPreferenceClickListener(
        new Preference.OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(final Preference preference) {
            AlertDialog.Builder builder = new AlertDialog.Builder(main);
            View v = main.getLayoutInflater().inflate(R.layout.signin, null);
            builder.setView(v);
            builder.setNegativeButton(
                android.R.string.cancel,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                  }
                });
            if (main.getGC().isConnected()) {
              ((TextView) v.findViewById(R.id.signedin))
                  .setText(
                      main.getString(
                          R.string.signed_in,
                          Games.Players.getCurrentPlayer(main.getGC()).getDisplayName()));
              v.findViewById(R.id.sign_in_button).setVisibility(View.GONE);
              builder.setPositiveButton(
                  R.string.sign_out,
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      main.signOut();
                      preference.setSummary(main.getString(R.string.sign_in));
                      dialog.dismiss();
                    }
                  });
            }
            final Dialog d = builder.create();

            if (!main.getGC().isConnected()) {
              v.findViewById(R.id.signedin).setVisibility(View.GONE);
              v.findViewById(R.id.sign_in_button)
                  .setOnClickListener(
                      new View.OnClickListener() {
                        @Override
                        public void onClick(final View v) {
                          // start the asynchronous sign in flow
                          main.beginSignIn();
                          d.dismiss();
                        }
                      });
            }
            d.show();
            return false;
          }
        });
    // If created for the first time, the GameClient should be setup and be
    // connected, but when recreating the fragment (due to orientation
    // change for example), then the fragment's onCreate is called before
    // the new GamesClient is setup. In this case, just use the player name
    // saved in the savedInstanceState bundle
    if ((savedInstanceState == null && main.getGC().isConnected())
        || (savedInstanceState != null && savedInstanceState.containsKey("player"))) {

      account.setSummary(
          main.getString(
              R.string.signed_in,
              savedInstanceState == null
                  ? Games.Players.getCurrentPlayer(main.getGC()).getDisplayName()
                  : savedInstanceState.getString("player")));
    }
  }