elyar abad
elyar abad

Reputation: 788

Why VOLLEY retrieves the same data with differing parameters?

I'm facing some kind of weird trouble with volley:

When I retrieve data with parameter a for the first time, there's nothing evil. However, all the next responses will be as same as the first one even though the parameter a is altered. Rerunning the app results all the mentioned. What could be the problem?

volley codes:

private void select() {
        Response.Listener<String> listener = new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
            //someCodes    
            }
        };
        Response.ErrorListener errorListener = new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
            //someCodes
            }
        };
        StringRequest request = new StringRequest(Request.Method.POST, "link", listener, errorListener) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> params = new HashMap<>();
                params.put("key", "value");
                return params;
            }
        };
        RequestQueue queue = Volley.newRequestQueue(activity.this);
        queue.add(request);
    }

`

Also, some changes are exerted on my server host; respecting this issue which php versions are suitable for designing an android web service, due to such a log: "stagefright/1.2 (Linux;Android 4.4.4)" when downloading mp3 files which counters another kind of problem. could it be related to the volley issue?

php codes:

<?php
$a = $_REQUEST['key'];
try {
    $connection = new PDO("mysql:host=name;dbname=db", "sq", "aabsabss");
    $connection->exec('set names utf8');
    $selectQuery = "SELECT * FROM  table WHERE cul = '$a'";
    $result = $connection->query($selectQuery);
    $outputArray = array();
    if ($result->rowCount()) {
        $rows = $result->fetchAll(PDO::FETCH_ASSOC);
        foreach ($rows as $resultArray) {
            $item = array();
            $item['a'] = $resultArray['a'];
            $item['b'] = $resultArray['b'];
            $item['c'] = $resultArray['c'];   
            $outputArray[] = $item;
        }
        echo json_encode($outputArray);
    }
} catch (Exception $exception) {
    echo $exception;
}

Any help is appreciated.

Upvotes: 0

Views: 95

Answers (1)

Rushikant Pawar
Rushikant Pawar

Reputation: 458

Reference : As per the request i am answering this question, so that in coming future if anyone come across this thread or issue, it might help them.

Why VOLLEY retrieves the same data with differing parameters?

Answer is not as short as the question, as in the last 8-10 years, google libraries and google android has changed a lot over the time. The answer is mostly theoretical which will at least give some insights to the developers.

1) I want to print hello world in everything as on startup

Now the world is not like Language C and you compile hello world any time. Yes i understand the developers needs the hello world assistance as the startup point in everything and then they build the concepts and the whole architecture over it. But the system resources are not for such stupid things. System resources and battery performance is now the most important factor.

2) Then when i can print hello world as starting point?

When your app is actively running and if only it is open to the user. Even then with restrictions over it and with proper development strategies.

3) What was the problem? Libraries are now AI enabled, which learns that this a repeating task and mostly previous result is getting used every time, so it never gives stress to the most of the system functionalities and saves the, time and resources of the system.

4) What was the needed?

request.setShouldCache(false);

5) Is the problem solved now?

BIG NO. Still the approach needs to be refined.

6) Then how can i refine it?

Avoid sending network requests like a child. Keeping requesting ALL THE TIME. Example : If you want to receive information about is your app user is registered or not then keep your own database day-wise. Remember if today have you requested it? If requested never request again for today. On tomorrow it will just request once and if requested already then on tomorrow it will never request again. Optimise it beyonf the limits of a single developer. So you must have 1000 developers..!!

7) Why the problem is still not solved then?

Look, you are no one special and android os is not for getting orders from your code and run it whenever you wants all the time..!! It will never run.

8) But android is running this code every time when i requests? Because you are on emulator. But in market there is no android. 99% are modified ROM which are colorOs, OxygenOS, FunTouch OS, MUIUI, ... They just allows applications to run in the background if the apps are from google ( maps, business, play store ) or from facebook or whatsapp or twitter. Your app will never run once removed from recents.

9) What i can do then Nothing if you are not a big business tycoon.

Upvotes: 1

Related Questions