How to get value returned from Get using Volley on android

1

In the case I want to know how to get only the value of the GET of the link "... / possess_cadastro" to enter the If or Else.

public class LoginRequest extends StringRequest {
private static final String REGISTER_REQUEST_URL = "http://192.168.30.12:5000/possui_cadastro";
private Map<String, String> params;

public LoginRequest(Response.Listener<String> listener) {
    super(Method.GET, REGISTER_REQUEST_URL, new Response.Listener<String>()
            {
                @Override
                public void onResponse(String response) {
                    // display response
                    if (response.toString() == "1") {


                        Context mContext = null;

                        Intent intent = new Intent(mContext, GpsActivity.class)
                                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        mContext.startActivity(intent);
                    }

                    else {

                        Context mContext = null;

                        Intent intent = new Intent(mContext, RegisterActivity.class)
                                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        mContext.startActivity(intent);

                    }

                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.d("Error.Response", String.valueOf(error));
                }
            });
    
asked by anonymous 21.09.2017 / 20:16

1 answer

1

The get method is correct. The if (response.toString () == "1") does not become true because in the variable there is a space before the number 1, so just apply the trim () function to remove the whitespace: if (response. toString (). trim () == "1")

    
06.10.2017 / 06:41