0

I am not able to explain the following issue.

I am working on an Android app. MainActivity has a method that calls a webservice to retrieve data.

I am checking the data and there is something very strange.

This is how am I getting the data:

private void getData() {


        // SqLite database handler
        db = new SQLiteHandler(this.getApplicationContext());

        // session manager
        session = new SessionManager(this.getApplicationContext());

        if (!session.isLoggedIn()) {
            logoutUser();
        }

        // Fetching user details from sqlite
        HashMap<String, String> user = db.getUserDetails();

        String name = user.get("name");
        String email = user.get("email");
        String imagen = user.get("imagen");
        String user_id = user.get("uid");
        String nivel_usuario = user.get("nivel_usuario");

        Log.d("HOLA PERFIL", "UID LOGEADO en sqlite: " + nivel_usuario);
        String id = user_id;

        loading = ProgressDialog.show(this,"Please wait...","Loading data...",false,false);

        String url = ConfigPerfil.DATA_URL+id;

        StringRequest stringRequest = new StringRequest(url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                loading.dismiss();
                showJSON(response);
            }
        },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                       // Toast.makeText(this,error.getMessage().toString(),Toast.LENGTH_LONG).show();
                    }
                });

        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(stringRequest);

    }

    private void showJSON(String response){
        Log.d("HOLA PERFIL", "RESPONSE: " + response);
        String name="";
        String email="";
        String imagen = "";
        String nivel_usuario = "";
        String cel_verificado = "";

        try {
            JSONObject jsonObject = new JSONObject(response);
            JSONArray result = jsonObject.getJSONArray(ConfigPerfil.JSON_ARRAY);
            JSONObject collegeData = result.getJSONObject(0);
            name = collegeData.getString(ConfigPerfil.KEY_NAME);
            email = collegeData.getString(ConfigPerfil.KEY_EMAIL);
            imagen = collegeData.getString(ConfigPerfil.KEY_IMAGEN);
            nivel_usuario = collegeData.getString(ConfigPerfil.KEY_NIVEL_USUARIO );
            cel_verificado = collegeData.getString(ConfigPerfil.KEY_CEL_VERIFICADO );



            if (cel_verificado.equals("0")){
                Toast.makeText(getApplicationContext(),
                        "CEL NUMBER NOT VERIFIED", Toast.LENGTH_LONG).show();

                //Get_Cel();
                Intent intent = new Intent(MainActivity.this,
                        VerificarCelActivity.class);
                startActivity(intent);
            }
            else
            {
                Toast.makeText(getApplicationContext(),
                        "CEL NUMBER VERIFIED", Toast.LENGTH_LONG).show();
            }



        } catch (JSONException e) {
            e.printStackTrace();
        }
        Log.d("HOLA PERFIL", "NIVEL USUARIO EN MAIN: " + nivel_usuario);
        Log.d("HOLA PERFIL", "NIVEL USUARIO EN MAIN CEL VERIFICADO: " + cel_verificado);

        txtNameU.setText(name);
        txtWebsite.setText(email);

        String cliente = "CLIENT";
        String  driver = "DRIVER";

        if (nivel_usuario.equals("1")) {
            txtTipo.setText(cliente);
        }
        if (nivel_usuario.equals("2")) {
            txtTipo.setText(driver);
        }
        Glide.with(this).load(urlProfileImg+imagen)
                .crossFade()
                .thumbnail(0.5f)
                .bitmapTransform(new CircleTransform(this))
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(imgProfile);


    }

This log shows me following:

JSONObject jsonObject = new JSONObject(response);

10-25 23:29:43.639 7117-7117/com.juarezserver.sdocks D/HOLA PERFIL: RESPONSE: {"result":[{"name":"yo","id":"141","email":"modestovasco@gmail.com","imagen":"blue-user-icon.png","nombre":"FName","apellidos":"LName","nivel_usuario":"1","cel_verificado":"0","celular":"+526566742909"}]}

Please take a look at the value at cel_verificado = 0

If I execute the PHP directly from the browser, the echoed result is:

{"result":[{"name":"yo","id":"141","email":"modestovasco@gmail.com","imagen":"blue-user-icon.png","nombre":"FName","apellidos":"LName","nivel_usuario":"1","cel_verificado":"1","celular":"+526566742909"}]}

And the real value in the database is:

enter image description here

I am working to find the source for the issue for over 3 hours, and no success. Any clue to how to detect the problem is very welcome

EDITED

I guess it has to do with some kind of cache...

mvasco
  • 4,965
  • 7
  • 59
  • 120
  • Are you sure that Java is targeting same URL as you're from browser? Error in data you're sending has nothing to do with Java. – Aleksandar Varicak Oct 26 '17 at 07:13
  • @PerunSS, yes, I am sure. And I have detected that after some while, after restarting the app, the data are ok again. I guess there is some cache involved. – mvasco Oct 26 '17 at 07:16
  • Is it significant that you do not fetch the cel_verificado field from sqlite after the declaration String nivel_usuario = user.get("nivel_usuario"); – Lew Perren Oct 26 '17 at 07:21
  • @BusinessPlanQuickBuilder, I think this is not the problem. The login process doesn´t include the phone number, and the data stored in sqlite are the main user data, not the phone number. At a second phase the user should verify his phone number, and this is the reason why i need to know it the cel number is verified or not. – mvasco Oct 26 '17 at 07:32
  • In that case, if only the cel_verificado field is wrong, I would look at the life cycle of your verification process. Especially to sequences of updating and retrieval of the cel_verificado field within that process. – Lew Perren Oct 26 '17 at 07:37
  • @BusinessPlanQuickBuilder, the field cel_verificado is not the only one that is wrong, it is the only one that can change in the remote server. As I have updated in my question, I have detected that after a while, when restarting the app, then the received data are ok, that´s why I guess there must be a cache or something similar in Volley requests. – mvasco Oct 26 '17 at 07:40
  • If cel_verificado is the only field that can change on the remote server then it is difficult to see how a cache issue would alter the results of the other fields in the first query. Still looks like the logic of your life cycle to me and restarting resets your logic, but I might be wrong. – Lew Perren Oct 26 '17 at 07:51
  • @BusinessPlanQuickBuilder, all data can change, but in this case, checking the process, I am only changing it to make it easy. For example, I put cel_verificado = 0 at the server. I launch the app, and the received value for cel_verificado=0. Now I verify the phone number, the app sends the new value for cel_verificado, and it works on the server, the new value there is 1. Now I launch the app again, the received value is 0. After a while, I launch the app again and then the received value is 1, as it should be. – mvasco Oct 26 '17 at 07:56
  • If other fields outside the verfication process manifest the same delay, then I guess cache is a possible issue, but I have not experienced problems before. – Lew Perren Oct 26 '17 at 08:06
  • 1
    @BusinessPlanQuickBuilder, I have been searching and confirmed,as default Volley uses cache for it requests. – mvasco Oct 26 '17 at 08:17
  • 1
    I guess an approach would be to force volley cache to flush particular record before retrieval. Helpful suggestion here https://stackoverflow.com/questions/24464610/how-to-clear-the-volley-cache-automatically – Lew Perren Oct 26 '17 at 08:20
  • @BusinessPlanQuickBuilder; i will take a look, thank you – mvasco Oct 26 '17 at 08:28

0 Answers0