开发者

Saving highscore to be for a game

So I am trying to use SharedPreferences to save the high score for my game. It seems to always cause a force close instead.开发者_Python百科

 @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();

 }

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜