Please never run a networking operation on the main (UI) thread .
Main thread is used to:
- interact with user.
- render UI components.
any long operation on it may risk your app to be closed with ANR message.
Take a look at the following :
you can easily use an AsyncTask
or a Thread
to perform your network operations.
Here is a great tutorial about threads and background work in android: Link