Skip to content

Instantly share code, notes, and snippets.

@soulfly
Last active February 6, 2017 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soulfly/7dc288748c25e9df8de96d021b610ac9 to your computer and use it in GitHub Desktop.
Save soulfly/7dc288748c25e9df8de96d021b610ac9 to your computer and use it in GitHub Desktop.
validate session token
String token = BaseService.getBaseService().getToken();
Date expirationDate = BaseService.getBaseService().getTokenExpirationDate();
// save to secure storage when your application goes offline or to the background
...
// recreate session on next start app
Date currentDate = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(currentDate);
cal.add(Calendar.HOUR, 2);
Date twoHoursAfter = cal.getTime();
if(expirationDate.before(twoHoursAfter)){
// valid token
}else{
// create a session
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment