So I’m trying to make a login and register menu, and when I try to use the code of the Documentation
“Backendless.UserService.register(user, new AsyncCallback<BackendlessUser>()”
The app just crashes when registering the new user, I’ve got an application class with the Backendless.initApp() on it, I’ve tried :
The code you showed is a blocking API call. If you made that call on the main UI thread, Android will not like it, since blocking calls are not allowed. Take a look at the paragraph marked Important on the following page in the docs for more details: https://backendless.com/docs/android/sync_and_async_calls.html
Thanks for answering! So I checked the page you linked me, and I’m still having some problems. First I’m not sure I fully understood if the blocking API call was my first try doing it or the second, but I can show you what I have right now.
So this is what happens when I press the “Register” button:
public void onClick(View v) {
if(etName.getText().toString().isEmpty() || etEmail.getText().toString().isEmpty() || etPassword.getText().toString().isEmpty() ||
etReEnter.getText().toString().isEmpty())
{
Toast.makeText(Register.this, “Please enter all details!”, Toast.LENGTH_SHORT).show();
}
else
{
if(etPassword.getText().toString().trim().equals(etReEnter.getText().toString().trim()))
{
String name = etName.getText().toString().trim();
String email = etEmail.getText().toString().trim();
String password = etPassword.getText().toString().trim();
//NEW USER FROM DATABASE
BackendlessUser user = new BackendlessUser();
user.setEmail(email);
user.setPassword(password);
showProgress(true);
new Thread(new Runnable(){
public void run(){
Backendless.UserService.register(user, new AsyncCallback<BackendlessUser>()
{ @Override
public void handleResponse(BackendlessUser response)
{
showProgress(false);
Toast.makeText(Register.this, “User sucessfully registered!”, Toast.LENGTH_SHORT).show();
Register.this.finish();
}
@Override
public void handleFault(BackendlessFault fault) {
Now I see that you create a thread and then inside of that thread you’re using a non-blocking API. I think that’s excessive. Either use non-blocking API or create a thread and use blocking in there.
Also, do you have the Backendless.initApp call somewhere in your app? It should be done before you use any of the APIs.
I was using a tutorial and everything was working fine, until I tried to register the user. The guy on the video had this same code, and it worked for him.