下記のようなコードで実装しているのですがリーダーボードを開いた後にバックキーでアプリに戻ってくると強制終了してしまうという問題で困っています。
ヒントでもよいのでよろしくお願いします。
下記のようなエラーが出ています。
java.lang.RuntimeException:
at android.app.ActivityThread.deliverResults (ActivityThread.java:4339)
at android.app.ActivityThread.handleSendResult (ActivityThread.java:4382)
at android.app.ActivityThread.-wrap19 (Unknown Source)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1654)
at android.os.Handler.dispatchMessage (Handler.java:105)
at android.os.Looper.loop (Looper.java:251)
at android.app.ActivityThread.main (ActivityThread.java:6563)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:240)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:767)
Caused by: java.lang.IllegalArgumentException:
at package.HighScoreActivity.onActivityResult (Unknown Source:2)
at android.app.Activity.dispatchActivityResult (Activity.java:7235)
at android.app.ActivityThread.deliverResults (ActivityThread.java:4335)
import android.content.Intent; import android.content.IntentSender; import android.os.Handler; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.games.Games; import com.google.android.gms.games.Player; public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks,GoogleApiClient.OnConnectionFailedListener{ private GoogleApiClient mGoogleApiClient; private boolean mIntentInProgress; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); mGoogleApiClient.connect(); } //初期設定 public void init() { // 各種リスナー登録とGoogleAPIで利用するAPIやスコープの設定 mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Games.API).addScope(Games.SCOPE_GAMES) .build(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 100) { mIntentInProgress = false; if (resultCode != RESULT_OK) { // エラーの場合、resultCodeにGamesActivityResultCodes内の値が入っている return; } if (!mGoogleApiClient.isConnected()) { mGoogleApiClient.reconnect(); } } } @Override public void onConnected(Bundle bundle) { // プレイヤー情報取得 Player p = Games.Players.getCurrentPlayer(mGoogleApiClient); // 試しにプレイヤー名を表示 String displayName = "???"; if (p != null) { displayName = p.getDisplayName(); } Toast.makeText(this, String.format("%s でログインしています。", displayName), Toast.LENGTH_SHORT).show(); } @Override public void onConnectionSuspended(int i) { mGoogleApiClient.connect(); } @Override public void onConnectionFailed(ConnectionResult connectionResult) { int errorCode = connectionResult.getErrorCode(); // サインインしていない場合、サインイン処理を実行する if (errorCode == ConnectionResult.SIGN_IN_REQUIRED && !mIntentInProgress && connectionResult.hasResolution()) { try { mIntentInProgress = true; connectionResult.startResolutionForResult(this, 100); } catch (IntentSender.SendIntentException e) { mIntentInProgress = false; mGoogleApiClient.connect(); } } } //全国ランキング表示 public void worldRanking(View view){ startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient,getResources().getString(R.string.ranking_id)),100); } }
あなたの回答
tips
プレビュー