应用程序崩溃时提交比分领先谷歌播放 [英] App crash when is submitting score leaderboard Google Play

查看:242
本文介绍了应用程序崩溃时提交比分领先谷歌播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些问题,我的Andr​​oid应用程序。

I have some problems with my android application.

我用谷歌与排行榜玩游戏的服务。我导入所有的图书馆,我做的一切了S需要...

I use google play games services with leaderboards. I import all the libraries, I do all that s needed...

在我的主要活动我按照谷歌developper文档这里我用

In my main activity I follow the Google developper documentation here and I use:

mClient.connect();

有关的连接,以及工作的。

for the connection and that works.

在比赛结束后,我试图提交了比分。我看到了,我可以把mClient静态的其他活动使用它的论坛。所以我称之为的onCreate:

At the end of the game, I try to submit the score. I saw on forums that I can put mClient in static to use it in the other activity. So I call in onCreate :

Games.Leaderboards.submitScore(MainActivity.mClient, getString(R.string.class_1), myscore);

但应用程序崩溃时,分数提交。我有这些错误:

But the app crash when score is submitting. I have these error:

12-14 15:37:24.856: E/AndroidRuntime(19613): FATAL EXCEPTION: main
12-14 15:37:24.856: E/AndroidRuntime(19613): java.lang.RuntimeException: Unable to resume activity {com.test.app/com.test.app.Result}: java.lang.IllegalStateException: GoogleApiClient must be connected.
12-14 15:37:24.856: E/AndroidRuntime(19613):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2141)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2156)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1680)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at android.app.ActivityThread.access$1500(ActivityThread.java:121)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at android.os.Looper.loop(Looper.java:130)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at android.app.ActivityThread.main(ActivityThread.java:3701)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at java.lang.reflect.Method.invokeNative(Native Method)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at java.lang.reflect.Method.invoke(Method.java:507)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at dalvik.system.NativeStart.main(Native Method)
12-14 15:37:24.856: E/AndroidRuntime(19613): Caused by: java.lang.IllegalStateException: GoogleApiClient must be connected.
12-14 15:37:24.856: E/AndroidRuntime(19613):    at com.google.android.gms.common.internal.o.a(Unknown Source)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at com.google.android.gms.games.Games.c(Unknown Source)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at com.google.android.gms.games.internal.api.LeaderboardsImpl.submitScore(Unknown Source)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at com.google.android.gms.games.internal.api.LeaderboardsImpl.submitScore(Unknown Source)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at com.test.app.Result.onResume(Result.java:129)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at android.app.Activity.performResume(Activity.java:3832)
12-14 15:37:24.856: E/AndroidRuntime(19613):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2131)
12-14 15:37:24.856: E/AndroidRuntime(19613):    ... 12 more

在开始的时候,写GoogleApiClient必须连接,而是mClient连接。
为此我也尝试在静态的,而是在应用程序崩溃也提交分数在MainActivity没有mClient。

At the beginning, it write "GoogleApiClient must be connected" but "mClient" is connected. Therefor I try also to submit score in the MainActivity without mClient in static but the app crash also.

推荐答案

有关管理谷歌API客户端最好的做法是为每一项活动,以维护自己的客户端的状态。查看更详细的讨论了这个问题:<一href=\"http://stackoverflow.com/questions/16827839/access-google-plus-client-from-multiple-activities\">Access谷歌Plus客户端从多个活动的。

The best practice for managing the Google API client is for each activity to maintain its own client state. See this question for more detailed discussion: Access google plus client from multiple activities.

用户体验将签署在对主要活动,然后在比赛结束的活动,检查client.isConnected()(和呼叫连接,如果没有连接),那么一旦连接提交比分。这样,你会在调用API之前请确保您有一个有效的客户端。

The user experience will be signing in on the "main activity", and then in the activity at the end of the game, check for client.isConnected() (and call connect if not connected) then once connected submit the score. This way, you will make sure you have a valid client before calling the API.

这篇关于应用程序崩溃时提交比分领先谷歌播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆