networkonmainthread
OkHttp Library – NetworkOnMainThreadException on simple post
You should use OkHttp’s async method. public static final MediaType JSON = MediaType.parse(“application/json; charset=utf-8”); OkHttpClient client = new OkHttpClient(); Call post(String url, String json, Callback callback) { RequestBody body = RequestBody.create(JSON, json); Request request = new Request.Builder() .url(url) .post(body) .build(); Call call = client.newCall(request); call.enqueue(callback); return call; } And then your response would be handled … Read more
Android – android.os.NetworkOnMainThreadException
NetworkOnMainThreadException: The exception that is thrown when an application attempts to perform a networking operation on its main thread. You should call sendfeedback method on asynctask then only above code will work. As webserver is taking lot of time to response main thread becomes unresponsive. To avoid it you should call it on another thread. … Read more
How can I fix ‘android.os.NetworkOnMainThreadException’?
NOTE : AsyncTask was deprecated in API level 30. AsyncTask | Android Developers This exception is thrown when an application attempts to perform a networking operation on its main thread. Run your code in AsyncTask: class RetrieveFeedTask extends AsyncTask<String, Void, RSSFeed> { private Exception exception; protected RSSFeed doInBackground(String… urls) { try { URL url = … Read more