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.
when I debugged my code I didn't get value of httpResponse and after this line
HttpResponse httpResponse = httpclient.execute(httpPost);
the problem occurred
public String login(String userName, String password){
try {
String url = URL+ "?flag="+"on"+"&user="+userName+"&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;
}