【发布时间】:2014-06-23 03:38:27
【问题描述】:
我正在尝试在我的游戏中编写代码以在计时器超时后保存分数。我有我的分数,我有我的计时器。我读过一些关于 SharedPreferences 和 SQLite 的文章。我知道我想保存前 10 名的高分,但 SharedPreferences 最好只保留 1 分。我正试图围绕 SQLite 进行思考,但我就是无法理解。任何人都可以帮助我找出一行代码来只保存前 10 名的分数。
这是我的 onFinish 代码:
public void onFinish() {
textViewTimer.setText("00:000");
timerProcessing[0] = false;
/** This is the Interstitial Ad after the game */
AppLovinInterstitialAd.show(GameActivity.this);
/** This creates the alert dialog when timer runs out */
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(GameActivity.this);
alertDialogBuilder.setTitle("Game Over");
alertDialogBuilder.setMessage("Score: " + count);
alertDialogBuilder.setCancelable(false);
alertDialogBuilder.setNeutralButton("Restart", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int id){
Intent restartGame = new Intent(GameActivity.this, GameActivity.class);
startActivity(restartGame);
finish();
}
});
alertDialogBuilder.setNegativeButton("Home", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int id) {
GameActivity.this.finish();
}
});
alertDialogBuilder.show();
【问题讨论】:
-
您是否使用 sqlite 在您的应用中获得前 10 名?
-
你开始为 sqlite db 编写代码了吗?如果没有,这里有一个很好的教程androidhive.info/2011/11/android-sqlite-database-tutorial
-
SQLite仅存储 10 位数字似乎不可行...在我看来,您应该坚持使用SharedPreferences。
标签: android sqlite sharedpreferences