If you want to write android code to connect on the internet you must under background process. You can use AsyncTask, Service or IntentService to do this. Writing another class that extends one of these classes for making web service calls will solve your problem.
Network operations can involve unpredictable delays. To prevent this from causing a poor user experience, always perform network operations on a separate thread from the UI. The AsyncTask class provides one of the simplest ways to fire off a new task from the UI thread.
just for share information…:D