使用 SharedPreferences,我想保存一个值(这将是上次更新日期的晚些时候)并加载它。在我关闭手机或强制关闭我的应用程序之前,它运行良好。它重置值。
这是代码:
public class feedPlayer extends Activity
{
public final static String PARAM_USERDETAILS="userdetails";
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
loadvars();
savevars();
}
public void savevars()
{
SharedPreferences parametres = this.getSharedPreferences(PARAM_USERDETAILS, MODE_PRIVATE);
Editor edit = parametres.edit();
edit.clear();
//Global.Maj = "maj"
TextView maj=(TextView) findViewById(R.id.datemaj);
edit.putString("gimli", Global.MAJ);
edit.commit();
maj.setText(Global.MAJ);
}
public void loadvars()
{
SharedPreferences parametres = this.getSharedPreferences(PARAM_USERDETAILS, MODE_PRIVATE);
TextView maj=(TextView) findViewById(R.id.datemaj);
String Smaj = parametres.getString("gimli", Global.MAJ);
maj.setText(Smaj);
}
}