Quantcast
Channel: How can I fix 'android.os.NetworkOnMainThreadException'? - Stack Overflow
Browsing all 191 articles
Browse latest View live

Answer by bpr10 for How do I fix 'android.os.NetworkOnMainThreadException'?

We can also use RxJava to move network operations to a background thread. And it's fairly simple as well. webService.doSomething(someData) .subscribeOn(Schedulers.newThread())-- This for background...

View Article


Answer by BalaramNayak for How do I fix...

The NetworkOnMainThread exception occurs because you have called some network operation on the default thread, that is, the UI thread. As per Android version Android 3 (Honeycomb) which is not allowed,...

View Article


Answer by Adnan Abdollah Zaki for How do I fix...

This exception is thrown when an application attempts to perform a networking operation on its main thread. If your task took above five seconds, it takes a force close. Run your code in AsyncTask:...

View Article

Answer by Krishna for How do I fix 'android.os.NetworkOnMainThreadException'?

You are not allowed to implement network operations on the UI thread on Android. You will have to use AsyncTask class to perform network related operations like sending API request, downloading image...

View Article

Answer by rObOtAndChalie for How do I fix...

You can actually start a new Thread, I had this problem before and solved it by this way.

View Article


Answer by RevanthKrishnaKumar V. for How do I fix...

Accessing network resources from the main (UI) thread cause this exception. Use a separate thread or AsyncTask for accessing a network resource to avoid this problem.

View Article

Answer by Nabin for How do I fix 'android.os.NetworkOnMainThreadException'?

In simple words, DO NOT DO NETWORK WORK IN THE UI THREAD For example, if you do an HTTP request, that is a network action. Solution: You have to create a new Thread Or use AsyncTask class Way: Put all...

View Article

Answer by Ponsuyambu Velladurai for How do I fix...

On Android, network operations cannot be run on the main thread. You can use Thread, AsyncTask (short-running tasks), Service (long-running tasks) to do network operations.

View Article


Answer by prat3ik-patel for How do I fix...

You have to simple add following line in manifest.xml after manifest tag <uses-permission android:name="android.permission.INTERNET"/> and in activity file add following code after binding...

View Article


Answer by msysmilu for How do I fix 'android.os.NetworkOnMainThreadException'?

Although above there is a huge solution pool, no one mentioned com.koushikdutta.ion: https://github.com/koush/ion It's also asynchronous and very simple to use: Ion.with(context)...

View Article

Answer by Kacy for How do I fix 'android.os.NetworkOnMainThreadException'?

This works. Just made Dr.Luiji's answer a little simpler. new Thread() { @Override public void run() { try { //Your code goes here } catch (Exception e) { e.printStackTrace(); } } }.start();

View Article

Answer by Gurpreet singh for How do I fix...

Use the below code to perform heavy tasks. // Your package here import java.util.List; import org.apache.http.NameValuePair; import android.app.Activity; import android.app.ProgressDialog; import...

View Article

Answer by Subhalaxmi for How do I fix 'android.os.NetworkOnMainThreadException'?

I solved this problem in a simple way... I added after oncreate StrictMode.enableDefaults(); and solved this. Or use Service or AsyncTask to solve this Note: Do not change SDK version Do not use a...

View Article


Answer by Kumarsunil for How do I fix 'android.os.NetworkOnMainThreadException'?

Android does not allow a separate process into the main activity thread, and the HTTP connection is an independent thread here. That is the reason you are getting the...

View Article

Answer by Vaishali Sutariya for How do I fix...

Put your code inside: new Thread(new Runnable(){ @Override public void run() { try { // Your implementation } catch (Exception ex) { ex.printStackTrace(); } } }).start(); Or: class DemoTask extends...

View Article


Answer by amardeep for How do I fix 'android.os.NetworkOnMainThreadException'?

This exception occurs due to any heavy task performed on the main thread if that performing task takes too much time. To avoid this, we can handle it using threads or executers...

View Article

Answer by Ashwin S Ashok for How do I fix...

The error is due to executing long running operations in main thread,You can easily rectify the problem by using AsynTask or Thread. You can checkout this library AsyncHTTPClient for better handling....

View Article


Answer by Novak for How do I fix 'android.os.NetworkOnMainThreadException'?

Just to spell out something explicitly: The main thread is basically the UI thread. So saying that you cannot do networking operations in the main thread means you cannot do networking operations in...

View Article

Answer by Oleksiy for How do I fix 'android.os.NetworkOnMainThreadException'?

Using Android Annotations is an option. It will allow you to simply run any method in a background thread: // normal method private void normal() { doSomething(); // do something in background }...

View Article

Answer by dhiraj kakran for How do I fix...

Use this in Your Activity btnsub.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated...

View Article
Browsing all 191 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>