samedi 10 décembre 2016

Android studio, set checkbox value from checked to unchecked, in the other activity

I have a "save" checkbox in the login activity. If the user check it, next time, when the application going to start , skip the login activity. Although, If User wants to logout, the checkbox in the login activity going to set unchecked. This problem, what I can't solve.

Login Activity the saveing part:

saveLogin = loginPreferences.getBoolean("saveLogin", false);
    if (saveLogin == true) {
        etEmail.setText(loginPreferences.getString("email", ""));
        etPassword.setText(loginPreferences.getString("password", ""));
        saveLoginCheckBox.setChecked(true);
    //    editor.putBoolean("checked", true);

     /*   editor.putString("email", "etEmail"); // Storing string
        editor.putString("password", "etPassword"); // Storing string*/

        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(etEmail.getWindowToken(), 0);

        String email = etEmail.getText().toString();
        String password = etPassword.getText().toString();

        if (saveLoginCheckBox.isChecked()) {
            loginPrefsEditor.putBoolean("saveLogin", true);
            loginPrefsEditor.putString("email", email);
            loginPrefsEditor.putString("password", password);
            loginPrefsEditor.commit();
        } else {
            loginPrefsEditor.clear();
            loginPrefsEditor.commit();
        }

        Backendless.UserService.login(email, password, new AsyncCallback<BackendlessUser>() {
            @Override
            public void handleResponse(BackendlessUser response) {
                Toast.makeText(getApplicationContext(),"Sikeres bejelentlezés",Toast.LENGTH_SHORT).show();

                Intent loginIntent = new Intent(LoginActivity.this, CategoryActivity.class);
                LoginActivity.this.startActivity(loginIntent);



            }

            @Override
            public void handleFault(BackendlessFault fault) {
                Toast.makeText(getApplicationContext(),"Sikertelen bejelentlezés",Toast.LENGTH_SHORT).show();
            }
        });
    }

And the User activity.... This part, where is a logout button:

 bLogout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Backendless.UserService.logout(new AsyncCallback<Void>() {
                    @Override
                    public void handleResponse(Void response) {


                        finish();

                        Intent logoutIntent = new Intent(UserAreaActivity.this, LoginActivity.class);
                        UserAreaActivity.this.startActivity(logoutIntent);
                    }
                    @Override
                    public void handleFault(BackendlessFault fault) {
                        Toast.makeText(getApplicationContext(),"Nem sikerült kijelentkezni!",Toast.LENGTH_SHORT).show();
                    }
                });

            }
        });

Aucun commentaire:

Enregistrer un commentaire