我正在为我的Android应用程序使用Parse服务器,但是当我单击回调按钮时,我单击后很长时间才得到记录的信息,但实际上没有任何反应-它不登录或注册我的用户。它也不会在logcat中显示任何错误,所以我真的不知道出了什么问题
这是我的活动-
public class MainActivity extends AppCompatActivity implements View.OnClickListener, View.OnKeyListener {
EditText tvID, tvPassword;
TextView tvLoginOrRegister;
Button signupButton;
LinearLayout backgroundLayout;
ImageView logoImageView;
Boolean signupModeActive = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
}
private void onLoginOrSignButtonClicked() {
Log.i("button", "was clicked");
String user = tvID.getText().toString();
String pass = tvPassword.getText().toString();
if (user.isEmpty() || pass.isEmpty()) {
Toast.makeText(MainActivity.this, "user & pass are required", Toast.LENGTH_SHORT).show();
} else {
if (signupModeActive) {
//We are going to signup
signup(user, pass);
} else {
//We are going to log in
login(user, pass);
}
}
}
private void login(String user, String pass) {
ParseUser.logInInBackground(user, pass, new LogInCallback() {
@Override
public void done(ParseUser user, ParseException e) {
if (user != null) {
Toast.makeText(MainActivity.this, "login okay", Toast.LENGTH_SHORT).show();
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> objects, ParseException e) {
if (e == null && objects != null){
Log.i("list of users", objects.toString());
} else {
Log.i("users list error", e.getMessage());
}
}
});
} else {
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}
private void signup(String user, String pass) {
ParseUser newUser = new ParseUser();
newUser.setUsername(user);
newUser.setPassword(pass);
newUser.signUpInBackground(new SignUpCallback() {
@Override
public void done(ParseException e) {
Log.i("callback", "came back from callback");
if (e == null) {
Log.i("signup", "success");
Toast.makeText(MainActivity.this, "signup success", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btnRegister:
onLoginOrSignButtonClicked();
break;
case R.id.tvLoginOrRegister:
Log.i("switch", "was tapped");
if (signupModeActive) {
setSignupOrLoginText(false, "Login", "Or, Signup");
} else {
setSignupOrLoginText(true, "Sign Up", "Or, Login");
}
break;
case R.id.logoImageview:
case R.id.backgroundLayout:
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
break;
}
}
private void setSignupOrLoginText(Boolean login, String buttonText, String textviewText) {
signupModeActive = login;
signupButton.setText(buttonText);
tvLoginOrRegister.setText(textviewText);
}
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if (i == KeyEvent.KEYCODE_ENTER && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
onLoginOrSignButtonClicked();
}
return false;
}
private void initViews() {
tvID = findViewById(R.id.tvId);
tvPassword = findViewById(R.id.tvPassword);
signupButton = findViewById(R.id.btnRegister);
tvLoginOrRegister = findViewById(R.id.tvLoginOrRegister);
backgroundLayout = findViewById(R.id.backgroundLayout);
logoImageView = findViewById(R.id.logoImageview);
signupButton.setOnClickListener(this);
tvLoginOrRegister.setOnClickListener(this);
tvPassword.setOnKeyListener(this);
logoImageView.setOnClickListener(this);
backgroundLayout.setOnClickListener(this);
}
}
如前所述,在logcat上没有出现关于错误或信息的任何内容,因此我真的不知道为什么它没有响应。希望有人能指出我做错了。