Always returning false as boolean value

Jacky

After user selecting area, there is a function called checkCoverageGuest(). This function checks whether selected area by the user is under coverage for that restaurantor not. If the restaurant is under coverage, then checkCoverageGuest() will return true value. When there is no coverage for that restaurant, checkCoverageGuest() will return false.

If the value is true then, it proceed to the next level which is checkout. If the value is false, the screen will display toast error message that the selected restaurant is not under coverage.

Right now, every this coming out from this function checkCoverageGuest() as false.

Here is my code.

private boolean checkCoverageGuest() {
    try {
        String url;
        if (appPrefs.getLanguage().equalsIgnoreCase("ar"))
            url = LinksConstants.TEST_SERVER_URL
                    + LinksConstants.SEARCH_COVERAGE_AREA;
        else
            url = LinksConstants.TEST_SERVER_URL
                    + LinksConstants.SEARCH_COVERAGE_AREA;

        Intent startingIntent = getIntent();
        city_id = getIntent().getStringExtra("id");

        RequestParams params = new RequestParams();
        params.put("area", city_id);

        NetworkRestClient.post(url, params, new JsonHttpResponseHandler() {
            @Override
            public void onStart() {
                super.onStart();
                progressActivity.showLoading();
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                progressActivity.showContent();
                JSONObject[] restaurants_arr = null;

                hasCoverageGuest = true;
                try {
                    if (response != null) {

                        JSONArray restaurants = response.getJSONArray("restaurants");

                        // if restaurants deliver to that area
                        if (!restaurants.getString(0).equals("null")) {
                            restaurants_arr = new JSONObject[restaurants.length()];

                            int has_coverage = 1; // assume coverage is there..

                            for (int j = 0; j < Utils.cart_restaurants.size(); j++) {
                                RestaurantModel restaurant = Utils.cart_restaurants.get(j);
                                String restaurantCartID = restaurant.getId();

                                boolean found = false;
                                for (int i = 0; i < restaurants.length(); i++) {
                                    restaurants_arr[i] = restaurants.getJSONObject(i);

                                    String restaurantID = restaurants_arr[i].get("restaurant_id").toString();

                                    if (restaurantCartID.equals(restaurantID)) {
                                        found = true;
                                        break;
                                    }
                                }  //end of inner for
                                if (found == false) {
                                    Toast.makeText(CheckoutActivity.this, "There is no coverage for the Selected Area ", Toast.LENGTH_SHORT).show();
                                    hasCoverageGuest = false;
                                    break;
                                }

                            }
                            //end of outer for
                        } //end of if

                        else //if restaurants don't deliver to that area
                        {
                            hasCoverageGuest = false;
                        }

                    } // end of if response != null


                } // end of try

                catch (Exception ex) {
                    GSLogger.e(ex);
                    showError();
                }

            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String errorResponse, Throwable throwable) {
                super.onFailure(statusCode, headers, errorResponse, throwable);

                showError();

                if (AppConstants.DEBUG_MODE)
                    showToast(errorResponse);
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
                super.onFailure(statusCode, headers, throwable, errorResponse);

                showError();
            }
        });

    } catch (Exception ex) {
        GSLogger.e(ex);
        showError();
    }
    return hasCoverageGuest;
}
Lluis Felisart

Your private boolean checkCoverageGuest() method returns before public void onSuccess() is executed, this is the reason for checkCoverageGuest() always returning false.

If you need to execute something after you get the hasCoverageGuest good value then excute it inside onSucess()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

shared preference Boolean is always returning false

Boolean in my object always returning false

Function returning always false when using a Boolean on my statement

The boolean return statement inside a for loop and if statement is always returning false in java

Python code Always returning None boolean when False should be returned

Boolean always returning as true?

if condition always returning False

function always returning false

if statement always returning false

withContext is always returning false

Using Gson to parse string to object. Boolean value is always false

Asp dropdown list boolean value is always set to false?

Android Retrofit2 parsing boolean value always false

form validation is always returning false value without even validating

Stuck with boolean always returning TRUE

Boolean function always returning true

Boolean Function Always Return False

Boolean values return false always

A Boolean function returning a value

Bcrypt compare always returning false

Append always returning false statement

My resultset is always returning false

File exists always returning false

Always returning false | Javascript | objects

If statement in C always returning false

Radio buttons always returning value of false to MySQL Database, regardless of specified value?

In application.yml, boolean field is-enabled always getting read as default value false

Returning an Observable<boolean> from canActivate and redirect on false

Query not returning records with a boolean column set to FALSE?