我正在创建一个登录表单。当用户登录时,它将进入主页。
我创建了一个AsyncTask
的活动。这是我的代码的相关部分:
public class iniTask extends AsyncTask<String, Void, String> {
private ProgressDialog Dialog = new ProgressDialog(GPSTracerActivity.this);
protected void onPreExecute() {
Dialog.setMessage("Connect to server...");
Dialog.show();
}
protected String doInBackground(String... url_req) {
String url = url_req[0];
try {
Log.v("doing background", executeHttpGet(url));
return executeHttpGet(url);
} catch(Exception e) {
Log.v("Exception doing background","Exception:"+e.getMessage());
return "";
}
}
protected void onPostExecute(String result) {
try {
Dialog.dismiss();
// here when thing go wrong
startNewAction(result);
} catch(Exception e) {
Log.v("Exception process response","Exception:"+e.getMessage());
}
}
}
这是startNewAction(result)
:
public void startNewAction(String result){
if (result.substring(0, 6) == "300 OK"){
Intent i = new Intent(GPSTracerActivity.this, Home.class);
startActivity(i);
}
}
任务正确启动,但当我拨打startNewAction(result)
时,
它不会调用新活动。为什么呢?
注意:当我启用if结构来测试字符串== 300 OK它不起作用!为什么
我在logcat
中看到了这一点:
07-16 14:57:23.345: WARN/InputManagerService(37): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40777ee0
答案 0 :(得分:0)
在你的onPostExecute中首先关闭对话框。
Dialog.dismiss();
答案 1 :(得分:0)
我刚刚找到了解决方案,因为我比较字符串的方式存在错误,
应该是,
if (result.substring(0, 6).equals("300 OK") ){
Intent i = new Intent(GPSTracerActivity.this, Home.class);
startActivity(i);
}
无论如何,感谢您的想法!!!