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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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