这里是一个用户凭据检查的模拟,大部分代码是由 Android Studio 生成的。如果 user:pass 不存在,它会进行注册,但我不确定应该将用户发送到主要 Activity 的位置。请查看checking mail & pass
部分。
/**
* Represents an asynchronous login/registration task used to authenticate
* the user.
*/
public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... params) {
// TODO: attempt authentication against a network service.
try {
// Simulate network access.
Thread.sleep(1000);
} catch (InterruptedException e) {
return false;
}
// checking mail & pass
for (String credential : DUMMY_CREDENTIALS) {
String[] pieces = credential.split(":");
if (pieces[0].equals(mEmail)) {
// Account exists, return true if the password matches.
return pieces[1].equals(mPassword);
}
}
// TODO: register the new account here.
Intent i = new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(i);
return true;
}
@Override
protected void onPostExecute(final Boolean success) {
mAuthTask = null;
showProgress(false);
if (success) {
finish();
} else {
mPasswordView.setError(getString(R.string.error_incorrect_password));
mPasswordView.requestFocus();
}
}
@Override
protected void onCancelled() {
mAuthTask = null;
showProgress(false);
}
}
在 user:pass 正确后,我从哪里开始主要 Activity ?
最佳答案
我现在找到了。
在 if (success)
关于android - 用户登录成功启动mainActivity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18583386/