我正在創建登錄表單。當用戶登錄時,它將導致主頁。我創建了一個活動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)
, 它不調用一個新的活動。爲什麼?
注意:當我啓用如果結構來測試字符串== 300確定這是行不通的!爲什麼
我看到這個logcat
:
07-16 14:57:23.345: WARN/InputManagerService(37): Window already focused, ignoring focus gain of: [email protected]
您是否檢查過它返回正確的結果? (即「300 OK」)另外,你的onPostExecute方法除了調用另一個方法之外什麼都不做,爲什麼不把你的邏輯放在那裏 - 特別是因爲它只有3行代碼! – Kenny
Thx我已經做了,但它什麼也沒有運行它沒有提出它顯示日誌貓的意圖活動,THAT是我我嘗試另一種方法來調用方法。 當我試圖把結構,如果我不使用,如果它會顯示另一個意圖,任何想法出現問題發生? – sayvortana
不太清楚你的問題是什麼,你發佈的錯誤來自視圖和輸入方法(如軟鍵盤)之間交互的框架類。您在嘗試打開的活動中使用鍵盤輸入嗎? – Kenny