Android Studio Database Connection using JSON

Asked

Viewed 137 times

0

I am with the following problem, I am making an app q contains login and user registration and I am using PHP and JSON code for this. However I checked my Response.Listener is never called, the execution jumps it... The code that’s on Main:

Response.Listener<String> responseListener = new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {

                        Toast.makeText(Register.this, "entrou", Toast.LENGTH_SHORT).show();

                        JSONObject jsonObject = new JSONObject(response);
                        boolean success = jsonObject.getBoolean("success");

                        if(success)
                        {
                            Toast.makeText(Register.this, "Entrou", Toast.LENGTH_SHORT).show();
                        }
                        else
                        {
                            Toast.makeText(Register.this, "Erro", Toast.LENGTH_SHORT).show();
                        }

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            };

And this is my Registerrequest:

public class RegisterRequest extends StringRequest {

private static final String REGISTER_REQUEST_URL = "kameo.com.br/control/ayzac_control_signin_mobile.php";
private Map<String, String> params;

public RegisterRequest(String email, String name, String nickname, String password, String date, String gender, Response.Listener<String> listener)
{
    super(Method.POST, REGISTER_REQUEST_URL, listener, null);
    params = new HashMap<>();
    params.put("userEmail", email);
    params.put("userName", name);
    params.put("userNickname", nickname);
    params.put("userPassword", password);
    params.put("userBirth", date);
    params.put("userGender", gender);
}

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

    I think you are using Volley. If so you need to add the request to Requestqueue.

  • RegisterRequest registerRequest = new RegisterRequest(email, username, usernick, password, birthdate, gender, responseListener);&#xA; RequestQueue queue = Volley.newRequestQueue(Register.this);&#xA; queue.add(registerRequest);&#xA; I put the Request Queue

  • Implement the Response.ErrorListener to see if there are any mistakes.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.