How to fix android.os.NetworkOnMainThreadException?

Posted by Editorial Staff | Updated on

Fix android.os.NetworkOnMainThreadException

This exception is thrown when an application attempts to perform a networking operation on its main thread. Run your code in AsyncTask:

How to execute the task:

In file you can add this line within your oncreate() method

Don’t forget to add this to AndroidManifest.xml file:

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@] Your question and answer will appear on and help other developers.

Related Questions & Answers