I an trying to login user using the following code. But user is not actually logged in and the last login property in bacendless console also does noit show anything. Please help.
public class Login extends Activity implements View.OnClickListener {
Button login_btn;
EditText username;
EditText passwd;
TextView register;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
Backendless.initApp(this, BackendSettings.Application_Id, BackendSettings.SecretKey, BackendSettings.appVersion);
login_btn = (Button) findViewById(R.id.login_button);
login_btn.setOnClickListener(this);
register = (TextView)findViewById(R.id.tv_register);
register.setOnClickListener(this);
}
@Override
public void onClick(View v) {
int id = v.getId();
switch (id){
case R.id.login_button:
username = (EditText) findViewById(R.id.et_username);
passwd = (EditText) findViewById(R.id.password);
CharSequence u_name = username.getText();
CharSequence password = passwd.getText();
LoadingCallback<BackendlessUser> loginCallback = createLoginCallback();
loginCallback.showLoading();
loginUser(u_name.toString(), password.toString(), loginCallback);
Toast.makeText(this,"Welcome",Toast.LENGTH_LONG).show();
Intent i = new Intent(Login.this,MainActivity.class);
startActivity(i);
break;
case R.id.tv_register:
Intent i1 = new Intent(Login.this, Register.class);
startActivity(i1);
break;
}
}
private LoadingCallback<BackendlessUser> createLoginCallback() {
return new LoadingCallback<BackendlessUser>(this,"Sending Login info")
{
public void handleResponse(BackendlessUser loggedUser){
super.handleResponse(loggedUser);
Toast.makeText(Login.this,String.format("Logged in : Name is %s", loggedUser.getObjectId()),Toast.LENGTH_LONG).show();
}
};
}
private void loginUser(String s, String s1, AsyncCallback<BackendlessUser> loginCallback) {
Backendless.UserService.login(s,s1,loginCallback);
}
}