Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

why textView can't execute here

in onPostExecute method textview at the end won’t execute its stays in "hello world" not with json data
i initialize it in the top
tried to put it outside the for loop no doesn’t help at all

@Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            pd.dismiss();
            StringBuilder stringBuilder = new StringBuilder();
            try {
                JSONArray array = new JSONArray(s);
                for(int i = 0 ; i<array.length(); i++) {
                    JSONObject object = array.getJSONObject(i);
                    String user = object.getString("username");
                    String address = object.getString("address");
                    JSONObject object1 = new JSONObject(address);
                    String city = object1.getString("city");
                    String geo = object1.getString("geo");
                    JSONObject jsonObject = new JSONObject(geo);
                    String lat = jsonObject.getString("let");
                    stringBuilder.append("username is " + user + " city is " + city + " let is " + lat + "\n");
                    textView.setText(stringBuilder.toString());

                }

            } catch (JSONException e) {
                e.printStackTrace();
            }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

asyncTask class was deprecated in API level 30.
https://developer.android.com/reference/android/os/AsyncTask

i recommend you use this solution:

Use the standard java.util.concurrent or Kotlin concurrency utilities instead.

ExecutorService exService  = Executors.newSingleThreadExecutor();
Handler handler=new Handler(Looper.getMainLooper);
exService.execute(new Runnnable(){
...
// your background works here 
//
//if you need change ui   use this:
handler.post(new Runnable(){
///change ui 
});

});

or if you want use AsyncTask use handler to run it on mainThread :

   new Hanndler(Looper.getMainLooper).post(new ...
    {
       textView.setText(stringBuilder.toString());
     });
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading