I am currently trying to setup user login and registration in my app. The first thing I am doing though is having my MainActivity check to see if a user is logged in and if they are, check if the session is valid. I am not sure if I am getting the ParseSession correctly, and if I am, I am not sure what to do at this point. (The docs are not very clear at showing how to accomplish this). Here is my code:
public class MainActivity extends AppCompatActivity {
ParseUser currentUser;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId(getResources().getString(R.string.parse_app_id))
.clientKey(getResources().getString(R.string.parse_client_key))
.server(getResources().getString(R.string.parse_server_url))
.build()
);
if (isFirstLaunch()) {
Toast.makeText(this, "This is the first launch", Toast.LENGTH_LONG).show();
}
if (!isUserLoggedIn()) {
Toast.makeText(this, "User is not logged in", Toast.LENGTH_LONG).show();
}
}
private boolean isFirstLaunch() {
return false;
}
private boolean isUserLoggedIn() {
currentUser = ParseUser.getCurrentUser();
if (currentUser == null) {
return false;
} else {
ParseSession.getCurrentSessionInBackground(new GetCallback<ParseSession>() {
@Override
public void done(ParseSession object, ParseException e) {
/*
* if session is valid
* return true
* if session is invalid
* run ParseUser.logOut()
* return false
*/
}
});
}
}
}