【发布时间】:2015-01-03 09:43:15
【问题描述】:
我曾尝试遵循 Google Play Services 的 Google 文档,但这是不可能的,因为 Google 文档是有史以来最糟糕的。
无论如何,我设法在我的应用中设置项目并添加 Google Play 服务,但是当用户更改活动时,我不知道如何保持播放器的连接状态。
我有 MainActivity,其中 扩展 BaseGameActivity,然后用户点击按钮 Play,我打开 GameActivity,我在其中玩游戏,然后当我完成游戏时,我想将分数提交到 Google Play 服务排行榜,但我不能,因为我似乎没有连接。
我用 BaseGameActivity 扩展 MyActivity
public class MainActivity extends BaseGameActivity
然后我在 GameActivity 上扩展这个:
public GameActivity extends Activity implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener
然后在 onCreate 上使用:
// Create the Google Api Client with access to Plus and Games
mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
.addOnConnectionFailedListener(this)
.addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
// add other APIs and scopes here as needed
.build();
然后当我完成游戏时,我尝试提交分数,但似乎我没有连接。
if(mGoogleApiClient.isConnected()){
Games.Achievements.unlock(mGoogleApiClient,
getString(R.string.app_name));
Games.Leaderboards.submitScore(mGoogleApiClient,
getString(R.string.number_guesses_leaderboard),
clickCounter);
}
【问题讨论】:
标签: android google-play-services google-play-games