2 回答

TA貢獻1871條經驗 獲得超13個贊
您聲明了loginPassed
var,但永遠不要在其中放置值。當您創建一個boolean
var 時,默認值是false
,它們運行時永遠不會輸入if(loginPassed)

TA貢獻1827條經驗 獲得超8個贊
首先你必須定義一個全局變量 loginPassed
Boolean loginPassed;
然后你必須執行 AsyncTask 來檢查這樣的用戶憑據 -
new UserLoginTask().execute();
現在在 AsyncTask 中,我們將檢查用戶的憑據并進行相應的操作
class UserLoginTask extends AsyncTask<Void, Integer, String>
{
String TAG = getClass().getSimpleName();
protected void onPreExecute (){
super.onPreExecute();
Log.d(TAG + " PreExceute","On pre Exceute......");
}
protected String doInBackground(Void...arg0) {
Log.d(TAG + " DoINBackGround","On doInBackground...");
if(validate(email, password))
loginPassed = true;
else
loginPassed = false;
return "";
}
protected void onProgressUpdate(Integer...a){
super.onProgressUpdate(a);
Log.d(TAG + " onProgressUpdate", "You are in progress update ... " + a[0]);
}
protected void onPostExecute(String result) {
super.onPostExecute(result);
Log.d(TAG + " onPostExecute", "" + result);
if(loginPassed){
Intent intent = new Intent(this, NavigationActivity.class);
intent.putExtra(EXTRA_MESSAGE, "Jefry");
startActivity(intent);
}else{
// There was an error; don't attempt login and focus the first
// form field with an error.
focusView.requestFocus();
}
}
}
添加回答
舉報