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();
}
}
}
添加回答
举报