Fast-Android-Networking icon indicating copy to clipboard operation
Fast-Android-Networking copied to clipboard

Syncrhronous Request Always False and Get connectionError

Open Hajriey opened this issue 5 years ago • 2 comments

I'm trying to use Sync Request but every time its response false and connectionError. But if I use Async Request, its response true/success. this is my code :

ANRequest request = AndroidNetworking.get(General.URLS + "User/GetStatus")
                .setPriority(Priority.HIGH)
                .build();

ANResponse response = request.executeForOkHttpResponse();

Log.d("SPLASH", "onCreate: " + response.isSuccess() + " " + response.getError().getErrorDetail());

this is responses

D/SPLASH: onCreate: false connectionError

Hajriey avatar Jun 19 '19 11:06 Hajriey

@Hajriey Did you find solution to this?

kafan1986 avatar Aug 31 '20 14:08 kafan1986

I did solve the issue. The problem lies that Android by default prevents calling network calls from UI thread. So the synchronous network call will work fine if called from a separate thread. If you want to call it from UI thread then add the following to your activity. I added it onCreate method after setContentView.

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);

kafan1986 avatar Sep 01 '20 01:09 kafan1986