你應該把它保存在一個文件,我建議使用SharedPreferences
,然後從那裏每次啓動應用程序時讀它,看看如果比賽正確或不正確。
要保存它:
SharedPreferences sp = context.getSharedPreferences("loginSaved", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString("username", "some user value");
editor.putString("password", "some password value");
editor.commit();
爲了得到它:
SharedPreferences sp = context.getSharedPreferences("loginSaved", Context.MODE_PRIVATE);
String username = sp.getString("username", null);
String password = sp.getString("password", null);
if(username != null && password != null){
// login automatically with username and password
}
else{
// login for the first time
}
我會想你指向這一點: [http://stackoverflow.com/questions/785973 [1] 這是什麼是最合適的方式存儲用戶設置在Android應用程序中[1]:http://stackoverflow.com/questions/785973/what-is-the-most-appropriate-way-to-store-user-settings-in-android-application – Thomas