您好先生在登录页面我正在验证服务器数据库中的用户名和密码。如果 net 存在意味着我的应用程序工作正常。如果我断开互联网意味着我的应用程序运行意味着它显示错误应用程序没有响应。如何消除此类错误
i try this code
if(name.equals("") || pass.equals(""))
{
Toast.makeText(Main.this, "Please Enter Username and Password", Toast.LENGTH_LONG).show();
}
else
{
try {
httpclient = new DefaultHttpClient();
httppost = new HttpPost("server url/login.php");
// Add your data
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("UserEmail", name.trim()));
nameValuePairs.add(new BasicNameValuePair("Password", pass.trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
response = httpclient.execute(httppost);
inputStream = response.getEntity().getContent();
data = new byte[256];
buffer = new StringBuffer();
int len = 0;
while (-1 != (len = inputStream.read(data)) )
{
buffer.append(new String(data, 0, len));
}
inputStream.close();
}
catch (IOException e) {
System.out.println(e);
//alertDialog.cancel();
}
if(buffer.charAt(0)=='Y')
{
Intent intent=new Intent(getApplicationContext(),ManagerHandset.class);
startActivity(intent);
}
else
{
Toast.makeText(Main.this, "Invalid Username or password", Toast.LENGTH_LONG).show();
}
}
}
});
如果我想断开我的网络意味着如何显示警报网络不可用