SharedPreferencesの文字列をチェックしてユーザー名とパスワードを保存したいので、ユーザー名とパスワードが空でないか空でなければ、ユーザー名とパスワードが空であれば、ログインページに移動します。SharedPreferencesの文字列が空であるかどうかを確認する方法* android
私はこのコードで乾杯を通してそれをチェックするために試みたが、私はこれを試した後、私はSharedPreferencesを得る。これは、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);
}
文字列が空でも空でもありません。
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文字列が空かヌルかを正しく確認するにはどうすればよいですか?
おかげ..
おかげ、その作業.. –
助けてうれしい。がんばろう! –
@AnupCowkurあなたはこれをチェックすることができますhttp://stackoverflow.com/questions/36959279/how-do-i-use-a-dialogue-in-my-android-app-just-before-the-start-of-サービス – Abhishek