I am doing my first login form




public class login extends Activity {
    /** Called when the activity is first created. */
    private EditText Email;
    private EditText Password;
    private Button btnLogin;
    private Button btnCancel;
    private TextView lblResult;
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ImageView image = (ImageView) findViewById(R.id.logo);
    Email = (EditText)findViewById(R.id.email);
    Password = (EditText)findViewById(R.id.password);
    btnLogin = (Button)findViewById(R.id.login_button);
    btnCancel = (Button)findViewById(R.id.cancel_button);
    lblResult = (TextView)findViewById(R.id.result);
    if (checkLoginInfo()) {
        String url = "http://www.blablabla/index.php";;
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
    }
    btnLogin.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
    String email = Email.getText().toString();
    String password = Password.getText().toString();
    final SharedPreferences mPreferences;
    mPreferences = getSharedPreferences("CurrentUser", MODE_PRIVATE);
    if(email.equals("guest") && password.equals("guest")){
        SharedPreferences.Editor editor=mPreferences.edit();
        editor.putString("Email", email);
        editor.putString("PassWord", password);
        editor.commit();
        String url = "http://www.blablabla/index.php";;
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
    }
    else {
        SharedPreferences.Editor editor=mPreferences.edit();
        editor.remove("Email");
        editor.remove("PassWord");
        editor.commit();
        lblResult.setText("Login failed. Email address and/or password 
doesn't exist.");
    }
}
});
btnCancel.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        // Close the application
        finish();
    }
});
}
private boolean checkLoginInfo() {
    final SharedPreferences mPreferences;
    mPreferences = getSharedPreferences("CurrentUser", MODE_PRIVATE);
    boolean email_set = mPreferences.contains("Email");
    boolean password_set = mPreferences.contains("PassWord");
    if ( email_set & password_set ) {
        return true;
    }
    else {
        return false;
    }
}
}





When I click on the cancel button checkLoginInfo()  returns true when you 
next try the app which is correct. If however I log into the url then close 
the browser then try the app again then I end up with the login form filled in 
with the login details instead of going to the url. What have I missed out 
please?





Thanks


-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to