how to check the SharedPreferences string is empty or null *android
<p>i want to check string in SharedPreferences, i used it to store username and password, so if username and password is not null or empty it will be directed to home, otherwise if the username and password is empty it will be directed to login page.</p>

<p>this is my <strong>code</strong> to check the SharedPreferences string, but it is not working..</p>

<pre><code>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);
    }
</code></pre>

<p>i tried to check it through toast with this code, and after i tried this, its always says that the SharedPreferences string is not null or empty..</p>

<pre><code>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();

           }
    }
 });
</code></pre>

<p>how can correctly check the SharedPreferences string whether its empty or null?</p>

<p>thanks..</p>
