Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将分数保存到Java Eclipse android文本文件中_Java_Android_Eclipse - Fatal编程技术网

将分数保存到Java Eclipse android文本文件中

将分数保存到Java Eclipse android文本文件中,java,android,eclipse,Java,Android,Eclipse,嗨,我已经创建了一个游戏,它有两个玩家,我想知道如何将两个玩家的分数保存到一个文本文件中,然后在应用程序再次打开时可以重复使用。我一直在研究共享首选项,但我遇到了一个难题,有人能帮我吗?谢谢 在启动程序活动中创建一个类似这样的类的实例 }使用本地数据库或Google Play服务在线存储分数。您需要详细说明您的问题。尝试发布您的读/写代码片段,并描述当前解决方案失败的地方共享首选项非常容易使用。但您的问题并不清楚。 public class SharedPrefs { public static

嗨,我已经创建了一个游戏,它有两个玩家,我想知道如何将两个玩家的分数保存到一个文本文件中,然后在应用程序再次打开时可以重复使用。我一直在研究共享首选项,但我遇到了一个难题,有人能帮我吗?谢谢

在启动程序活动中创建一个类似这样的类的实例


}

使用本地数据库或Google Play服务在线存储分数。您需要详细说明您的问题。尝试发布您的读/写代码片段,并描述当前解决方案失败的地方共享首选项非常容易使用。但您的问题并不清楚。
public class SharedPrefs {
public static String hScore="H_SCORE";
public static final String myPref = "MY_PREF" ;
public BaseGameActivity activity;
private SharedPreferences shpref;
public SharedPrefs(BaseGameActivity activity){
    this.activity=activity;
    shpref = activity.getSharedPreferences(myPref, Context.MODE_PRIVATE);
    if(!shpref.contains(hScore)){
        Editor editor = shpref.edit();
        editor.putString(hScore, "0");
        editor.commit();
    }

}
public void checkAndSetHscore(int score){
    if(score>Integer.parseInt(getHScore())){            
        Editor editor = shpref.edit();
        editor.putString(hScore, ""+score);
        editor.commit();        
    }
}
public String getHScore(){
    shpref = activity.getSharedPreferences(myPref, Context.MODE_PRIVATE);
    return shpref.getString(hScore, "");        
}