创建 AsyncTask 时出错
我正在创建一个登录表单。当用户登录时,将进入主页。
我创建了一个具有 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 结构来测试 string == 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
I'm creating a login form. When the user logs in, it will lead to the home page.
I create an activity that has an AsyncTask
. Here's the relevant part of my code:
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());
}
}
}
Here's startNewAction(result)
:
public void startNewAction(String result){
if (result.substring(0, 6) == "300 OK"){
Intent i = new Intent(GPSTracerActivity.this, Home.class);
startActivity(i);
}
}
The task starts correctly, but when I call startNewAction(result)
,
it does not call a new activity. Why?
NOTE : when i enable if structure to test string == 300 OK it is not work ! why
I see this in 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 onPostExecute 中,首先关闭对话框。
In your onPostExecute dismiss the dialog first.
我刚刚找到了解决方案,由于我比较字符串的方式而出现错误,
应该是,
无论如何,感谢您的想法!
I just found the solution,there is an error because of the way i compare the string,
It should be,
Anyway, Thanks for ideas !!!