我有一个以登录页面启动的应用程序,现在当用户使用 wifi 时它工作正常,但是当他/她切换到数据连接时,web 服务没有响应。在此之后,当用户手动强制停止/重新安装应用程序时,它再次在数据连接/wifi 上工作,但给出与上述相同的行为,我的代码如下:
public class Logg extends Activity {
EditText log, pw, tfld;
Button bt;
String logg, pww, resp ;
static String employidd;
ProgressDialog p;
private static String SOAP_ACTION = "MyName/CheckLogin"; // "http://tempuri.org/CheckLogin";
private static String NAMESPACE = "MyName"; // "http://tempuri.org/";
private static String METHOD_NAME = "CheckLogin";
private static String URL = "http://timetracker.e-pspl.com/erm-login/"; //"http://tdsw025.pcsolutions.com/ERMWeb/";
/* Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
log = (EditText) findViewById(R.id.logger1);
pw = (EditText) findViewById(R.id.pwwrs);
bt = (Button) findViewById(R.id.subb);
bt.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
logg = log.getText().toString();
pww = pw.getText().toString();
if (logg.equals("")) {
Toast.makeText(Logg.this, "Login ID cannot be blank",
Toast.LENGTH_SHORT).show();
}
if (pww.equals("")) {
Toast.makeText(Logg.this, "Password cannot be blank",
Toast.LENGTH_SHORT).show();
} else {
try {
new SoapLog().execute();
} catch (Exception e) {
Log.v("xcptn", e.toString());
}
}
}
});
}
private class SoapLog extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
// Initialize soap request + add parameters
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
// Use this to add parameters
request.addProperty("UserName", logg);
request.addProperty("Pwd", pww);
// Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
Log.v("req", request + "");
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
// this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
Log.v("envelope", envelope + "");
} catch (Exception e) {
e.printStackTrace();
}
try{
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject) envelope.bodyIn;
resp = result.toString();
Log.v("respmain", resp);
}catch(NullPointerException e){
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
p.dismiss();
if (resp != null) {
// // if (resp.contains("true")) {
// Intent one = new Intent(Logg.this, Second.class);
// startActivity(one);
// finish();
// // }
if (resp.contains("false")) {
Toast.makeText(Logg.this, "Invalid UserID/Password",
Toast.LENGTH_SHORT).show();
// StringTokenizer tokens = new StringTokenizer(resp, "=");
// String first = tokens.nextToken();
// String second = tokens.nextToken();
// Log.v("tag", first);
// Log.v("tag1", second);
} else {
String str[] = resp.split("=");
String tempStr[] = str[1].split(";");
employidd = tempStr[0];
Log.v("id", employidd);
Toast.makeText(Logg.this, "Success!!", Toast.LENGTH_SHORT)
.show();
Intent onne = new Intent(Logg.this, DateList.class);
onne.putExtra("ID", employidd);
startActivity(onne);
finish();
}
}
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
p = ProgressDialog.show(Logg.this, "", "Loading...");
}
}
}
什么可能导致这种行为?任何帮助将不胜感激..