保存的高分成为一个游戏 [英] Saving highscore to be for a game
问题描述
所以我试图使用共享preferences保存高的分数我的比赛。它似乎总是导致强制关闭代替。
So I am trying to use SharedPreferences to save the high score for my game. It seems to always cause a force close instead.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(new GameView(this));
SharedPreferences prefs = getSharedPreferences("pref" , MODE_PRIVATE);
gameView.highScore = prefs.getInt("highScore", 0);
Editor editor = prefs.edit();
editor.putInt("highScore", gameView.highScore);
editor.commit();
}
我使用的GameView面视图,这个类是只调用它。它wouldnt让我把共享preferences其他地方无GameView红线,所以我把它放在这里。虽然这是导致其强制关闭。我应该如何去解决这个。谢谢你。
I'm using surface view in the GameView so this class is just calling to it. It wouldnt let me put the SharedPreferences anywhere else without redlining it in GameView so I placed it here. Although this is causing it to force close. How should I go about fixing this. Thanks.
推荐答案
你有没有考虑使用第三方API来完成记分管理。我转向scoreNinja这些时间,但我相信有各地的其他很多选择。
Did you think about using a third party API to do score management. I am turning to scoreNinja these times but I am sure there are other many alternatives around.
它可以有助于更好的用户体验来比较其他球员,让您的应用程序更用了。
It can contribute to a greater user experience to compare against other players and make your app more used.
这篇关于保存的高分成为一个游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!