mercredi 22 juin 2016

How can I fix too many things happening Android Studio

The problem is definitely from this code.

 bRegister.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final String username = etuserame.getText().toString();
            final String email = etemail.getText().toString();
            final String password = etpassword.getText().toString();

            Response.Listener<String> responseListener = new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject jsonResponse = new JSONObject(response);
                        boolean success = jsonResponse.getBoolean("success");
                        if (success) {
                            Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
                            RegisterActivity.this.startActivity(intent);
                        } else {
                            AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
                            builder.setMessage("Register Failed")
                                    .setNegativeButton("Retry", null)
                                    .create()
                                    .show();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            };

            RegisterRequest registerRequest = new RegisterRequest(username, email, password, responseListener);
            RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
            queue.add(registerRequest);

when the user clicks register, It does not open the new activity and I get nothing in my database. I just get a cancelling event due to no window focus and too many processes running. This is my RegisterRequest class.

private Map<String, String> params;

public RegisterRequest(String username, String email, String password, Response.Listener<String> listener){
    /*
    NExt line means we are going to pass some information into the register.php
     */
    super(Method.POST, REGISTER_REQUEST_URL, listener, null);
    /*
    This is how we pass in the information from the register to the thing, we are using a hashmap
     */
    params = new HashMap<>();
    params.put("username", username);
    params.put("email", email);
    params.put("password", password);

}
/*
Volley needs to get the data so we do a get params
Which gives us this method
 */

@Override
public Map<String, String> getParams() {
    return params;
}

} Please Any HELP

Aucun commentaire:

Enregistrer un commentaire