ユーザー名とパスワードを保存するために使用される SharedPreferences の文字列を確認したいので、ユーザー名とパスワードが null または空でない場合はホームに送られ、それ以外の場合はユーザー名とパスワードが空の場合はログイン ページに送られます。
これは、SharedPreferences 文字列を確認するための私のコードですが、機能していません..
if(PreferenceConnector.USERNAME!=null){
Intent intent = new Intent(MainActivity.this,MainHome_Activity.class);
startActivity(intent);
} else {
Intent intent = new Intent(MainActivity.this,LoginFormPegawai_Activity.class);
startActivity(intent);
}
このコードでトーストを確認しようとしましたが、これを試した後、SharedPreferences string is not null or empty..
btn_logout_pegawai.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//remove the SharedPreferences string
PreferenceConnector.getEditor(this).remove(PreferenceConnector.USERNAME)
.commit();
PreferenceConnector.getEditor(this).remove(PreferenceConnector.PASSWORD)
.commit();
//checking the SharedPreferences string
if(PreferenceConnector.USERNAME!=null){
Toast.makeText(MainHome_Activity.this,"not null", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(MainHome_Activity.this,"null", Toast.LENGTH_SHORT).show();
}
}
});
SharedPreferences 文字列が空か null かを正しく確認するにはどうすればよいですか?
ありがとう..