Вот код моей активити. теперь ошибки нету, но оно просто не поключается. Тоесть, не вызывается OnConnected
package hakito.pencilrunner.Activities;
import android.content.IntentSender;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.games.Games;
import hakito.pencilrunner.Game.Game;
import hakito.pencilrunner.R;
public class FinishActivity extends AppCompatActivity implements View.OnClickListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
public static final String EXTRA_DISTANCE="distance";
GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_finish);
findViewById(R.id.buttonRestart).setOnClickListener(this);
client = new GoogleApiClient.Builder(this).addApi(Games.API).addScope(Games.SCOPE_GAMES).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
}
@Override
public void onClick(View v) {
switch (v.getId())
{
case R.id.buttonRestart:
Game.get().restart();
finish();
break;
}
}
@Override
protected void onStart() {
super.onStart();
client.connect();
}
@Override
protected void onStop() {
super.onStop();
client.disconnect();
}
@Override
public void onConnected(Bundle bundle) {
int dist = getIntent().getIntExtra(EXTRA_DISTANCE, 0);
Games.Leaderboards.submitScore(client, getString(R.string.leaderboard_best_score), dist);
startActivity(Games.Leaderboards.getLeaderboardIntent(client, getString(R.string.leaderboard_best_score)));
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
if(connectionResult.hasResolution())
{
try {
connectionResult.startResolutionForResult(this, 0);
client.connect();
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}else {
GooglePlayServicesUtil.showErrorDialogFragment(connectionResult.getErrorCode(), this, 0);
}
}
}