Click here to Skip to main content
15,891,713 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

According from : rest - How to make a synchronous call using Retrofit on Android - Stack Overflow[^]

if I use retrofit2 synchronously would make app crash, but I really need something that could return the value directly.

What I have tried:

I've ever used asycntask like this :

Java
public static class GetData extends AsyncTask<Void, Void, String> {

        @Override
        protected String doInBackground(Void... vd) {
            RequestHandler requestHandler = new RequestHandler();

            HashMap<String, String> params = new HashMap<>();
            params.put("user_id", "1");
            return requestHandler.sendPostRequest(URLs.GET_VIDEOS, params);
        }

        @Override
        protected void onPostExecute(String vdata){
            super.onPostExecute(vdata);
        }
    }


this could be return value directly when I call :
Java
new GetData().execute().get();


Note : I've ever used volley also, but volley incompatible with laravel, the result always GET never POST.

Q : Is there other solutions to get value data directly besides using asynctask?
I don't want to using asynctask because it caused my app slow.

Please someone help me

Thanks
Posted
Updated 1-Oct-20 1:14am
v2
Comments
[no name] 1-Oct-20 10:30am    
Async is not "slow"; it's about keeping the UI responsive; you just need to learn how to write and respond to async code and events.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900