I am using parse.com as my backend service for my Android application. I wish to make separation between my activities and parse, for this purpose I have created service class witch will bridge activities and parse (backend). Most parse functions are asynchronous and I don't really know how to handle them. For example if I want to login with a user I will call the service object that should execute login with parse login function. So here is my code in the activity:
LoginService login = new LoginService("username", "password");
login.login();
//from here it is not correct
if(login.getLoginStatus() == 2) {
//user loggedin
}...
and my service code is:
public LoginSrvice(String userName, String pass)
{
this.userName = userName;
this.pass = pass;
}
public void loginUser()
{
ParseUser.logInInBackground(userName, pass, new LogInCallback()
{
@Override
public void done(ParseUser user, ParseException e) {
if (user != null) {
logedIn = 1;
} else {
logedIn = 2;
}
}
});
}
public int getLoginStatus()
{
return logedIn;
}
My question is how should I do it right? how can i keep both activities and services separated but still wait for the response in the activity till the service class will get the callback from parse. Thanks for the HELP in advance!
.
stackoverflow.comm
No comments:
Post a Comment