android is hang while android don't find connection
<p>I am creating an android application but while(if?) server is not found, it will hang the tool kit (SDK/emulator?). 
I have attached my login code. Please help me to find the solution. I just want that if server is not available, my application will stay on at the login page without hanging itself.</p>

<p>when I debugged my code I didn't get value of httpResponse and after this line </p>

<pre><code>HttpResponse httpResponse = httpclient.execute(httpPost);
</code></pre>

<p>the problem occurred</p>

<pre><code>public String login(String userName, String password){
        try {
            String url = URL+ "?flag="+"on"+"&amp;user="+userName+"&amp;pass="+password;
            httpPost = new HttpPost(url);
            HttpResponse httpResponse = httpclient.execute(httpPost);
            int statuscode = httpResponse.getStatusLine().getStatusCode();
            if (statuscode == 200) {
                String responseMsg = getResponse(httpResponse); 
                return responseMsg;
            }else{
                Log.e(TAG, statuscode+"");
            }
        } catch (ClientProtocolException e) {
            Log.e(TAG, e.getMessage(),e);
        } catch (IOException e) {
            Log.e(TAG, e.getMessage(),e);
        }
        return null;
    }
</code></pre>
