Answer by Kacy for How can I fix 'android.os.NetworkOnMainThreadException'?
This works. I 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 can I fix...
Use the below code to perform heavy tasks.// Your package hereimport java.util.List;import org.apache.http.NameValuePair;import android.app.Activity;import android.app.ProgressDialog;import...
View ArticleAnswer by Subhalaxmi for How can I fix...
I solved this problem in a simple way...I added after oncreateStrictMode.enableDefaults(); and solved this.Oruse Service or AsyncTask to solve thisNote:Do not change SDK versionDo not use a separate...
View ArticleAnswer by Kumarsunil for How can I fix...
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 can 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 can 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...
View ArticleAnswer by Ashwin S Ashok for How can 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 can 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 the...
View ArticleAnswer by Oleksiy for How can 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 methodprivate void normal() { doSomething(); // do something in...
View ArticleAnswer by dhiraj kakran for How can 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 ArticleAnswer by perry for How can I fix 'android.os.NetworkOnMainThreadException'?
This is only thrown for applications targeting the Honeycomb SDK or higher. Applications targeting earlier SDK versions are allowed to do networking on their main event loop threads.The error is the...
View ArticleAnswer by Stevie for How can I fix 'android.os.NetworkOnMainThreadException'?
The accepted answer has some significant downsides. It is not advisable to use AsyncTask for networking unless you really know what you are doing. Some of the down-sides include:AsyncTask's created as...
View ArticleAnswer by Dhruv Jindal for How can I fix...
Network-based operations cannot be run on the main thread. You need to run all network-based tasks on a child thread or implement AsyncTask.This is how you run a task in a child thread:new Thread(new...
View ArticleAnswer by Kapil Vats for How can I fix...
You should not do any time-consuming task on the main thread (UI thread), like any network operation, file I/O, or SQLite database operations. So for this kind of operation, you should create a worker...
View ArticleAnswer by henry4343 for How can I fix 'android.os.NetworkOnMainThreadException'?
Do the network actions on another thread.For example:new Thread(new Runnable(){ @Override public void run() { // Do network action in this function }}).start();And add this to file...
View ArticleAnswer by rharvey for How can I fix 'android.os.NetworkOnMainThreadException'?
For me it was this:<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10" />The device I was testing my app on was 4.1.2 which is SDK Version 16!Make the sure the target version is the...
View ArticleAnswer by raihan ahmed for How can I fix...
This happens in Android 3.0 and above. From Android 3.0 and above, they have restricted using network operations (functions that access the Internet) from running in the main thread/UI thread (what...
View ArticleAnswer by venergiac for How can I fix 'android.os.NetworkOnMainThreadException'?
Do not use strictMode (only in debug mode)Do not change SDK versionDo not use a separate threadUse Service or AsyncTaskSee also Stack Overflow question:android.os.NetworkOnMainThreadException sending...
View ArticleAnswer by sivag1 for How can I fix 'android.os.NetworkOnMainThreadException'?
The top answer of spektom works perfect.If you are writing the AsyncTask inline and not extending as a class, and on top of this, if there is a need to get a response out of the AsyncTask, one can use...
View ArticleAnswer by Dr.Luiji for How can I fix 'android.os.NetworkOnMainThreadException'?
I solved this problem using a new Thread.Thread thread = new Thread(new Runnable() { @Override public void run() { try { //Your code goes here } catch (Exception e) { e.printStackTrace(); }...
View Article