Fast-Android-Networking
Fast-Android-Networking copied to clipboard
Syncrhronous Request Always False and Get connectionError
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 Did you find solution to this?
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);