Quick fix for NetworkOnMainThreadException

You could change it to: android:targetSdkVersion=”9″ API 10 corresponds to honeycomb, while 9 is gingerbread. This behavior is only seen in APIs 10 and above. However, I would advise against this. Instead, you should move any long running operations, or operations with the possibility of running for long into a background thread, like an AsyncTask. … Read more

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

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

NetworkOnMainThreadException [duplicate]

With honeycomb you can not perform a networking operation on its main thread as documentation says. For this reason you must use handler or asynctask. There is no another way to do it. here you can find 2 examples written in turkish about networking operation. maybe they help. 3. party kütüphane kullanmadan (ksoap2), (it includes … Read more