This exception is thrown when an application attempts to perform a networking operation on its main thread. Run the code in AsyncTask
How to execute the task:
In MainActivity.java file we can add this line within the oncreate()methodnew RetrieveFeedTask().execute(urlToRssFeed);Don't forget to add this to AndroidManifest.xmlfile: <uses-permission android:name="android.permission.INTERNET"/>
We should almost always run network operations on a thread or as an asynchronous task. But if we know better and are willing to accept the consequences, and must do network operations on the main thread, we can override the default behavior:
In the class,
ADD this permission in android manifest.xml file:
The app will (in areas of spotty internet connection) become unresponsive and lock up, the user perceives slowness and has to do a force kill, and you risk the activity manager killing your app and telling the user that the app has stopped.
Related Searches to How to fix android.os.NetworkOnMainThreadException ?
networkonmainthreadexception in android solutionandroid.os.networkonmainthreadexception httpclientandroid.os.networkonmainthreadexception okhttpandroid.os.networkonmainthreadexception in serviceandroid.os.networkonmainthreadexception retrofitandroid.os.networkonmainthreadexception httpurlconnectionandroid.os.networkonmainthreadexception rxjavanetworkonmainthreadexception android fixnetwork on main thread exception android socketerror in http connection android os networkonmainthreadexceptionandroid os networkonmainthreadexception how to solvehow to avoid android os networkonmainthreadexceptionfatal error android os networkonmainthreadexceptionandroid os networkonmainthreadexception at android os strictmode
Wikitechy Rated 5 / 5 based on 378284 reviews.
World's No 1 Animated self learning Website with Informative tutorials explaining the code and the choices behind it all.