private Button.OnClickListener login = new Button.OnClickListener() {
public void onClick(View v) {
String name = txtUsername.getText().toString();
String pwd = txtPwd.getText().toString();
if(name.equals("") || pwd.equals("")){
Toast.makeText(LoginActivity.this, "用户名密码均不能为空!", Toast.LENGTH_SHORT).show();
return;
}

String urlstr = URL + "?name=" + name + "&password=" + pwd;
//http请求
HttpGet request = new HttpGet(urlstr); 
DefaultHttpClient client = new DefaultHttpClient();
try {
HttpResponse response = client.execute(request);
int status = response.getStatusLine().getStatusCode();
if (status == HttpStatus.SC_OK) {
String rp = EntityUtils.toString(response.getEntity());
if(rp.equals("SUCCESS")){ //登录成功
//保存用户信息,以后不用再次登录
if(chkSaveuser.isChecked())
 SaveUserData();

//转到下个页面
Intent intent = new Intent(); 
intent.setClass(LoginActivity.this, GPSTimerActivity.class);
//传递参数,让下一个activity使用

Bundle bundle = new Bundle();  
bundle.putString("name",name);//
intent.putExtras(bundle);//传数据结束  
startActivity(intent);
     
LoginActivity.this.finish();//结束本activity
}else{ //不成功提示错误
Toast.makeText(LoginActivity.this, "用户名或密码错误!", Toast.LENGTH_SHORT).show();
return;
}
} else {
Toast.makeText(LoginActivity.this, "网络连接有问题,请重试!", Toast.LENGTH_SHORT).show();
}
} catch (ClientProtocolException e) {
Toast.makeText(LoginActivity.this, "登录错误,请重试!", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(LoginActivity.this, "登录错误,请重试!", Toast.LENGTH_SHORT).show();
} finally {
client.getConnectionManager().shutdown();
}
}
};