-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrefs.java
40 lines (30 loc) · 948 Bytes
/
Prefs.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.example.trivia.util;
import android.app.Activity;
import android.content.SharedPreferences;
public class Prefs {
private SharedPreferences preferences;
public Prefs(Activity activity) {
this.preferences = activity.getPreferences(activity.MODE_PRIVATE);
}
public void saveHighScore(int score)
{
int currentscore = score;
int last_score = preferences.getInt("high_score",0);
if (currentscore>last_score)
{
//we have a new high score
preferences.edit().putInt("high_score",currentscore).apply();
}
}
public int getHighScore()
{
return preferences.getInt("high_score",0);
}
public void setState(int index)
{
preferences.edit().putInt("index_state",index).apply();
}
public int getState() {
return preferences.getInt("index_state",0);
}
}