How to get value returned from Get using Volley on android

Asked

Viewed 47 times

1

In case I want to know how to get only the GET value of the link ".../posses_cadastro" to enter 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));
                }
            });

1 answer

1


The get method is right. if (Response.toString() == "1") does not become true because in the variable there is a space before the number 1, then just apply in the variable the function Trim() that removes whitespace: if (Response.toString(). Trim() == "1")

Browser other questions tagged

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