Skip to content

Instantly share code, notes, and snippets.

@vitovalov
Created March 27, 2015 21:25
Show Gist options
  • Save vitovalov/65044b39f5267494ccdb to your computer and use it in GitHub Desktop.
Save vitovalov/65044b39f5267494ccdb to your computer and use it in GitHub Desktop.
Get elapsed time from the first time user launched the app using SharedPreferences and Joda-Time
long lastLaunchedDateMillis = VITPreferencesUtils.getLongGeneric(PuzzleApp.getInstance(), "first_launch_date", -1);
DateTime current = new DateTime();
DateTime lastLaunchedDate = new DateTime(lastLaunchedDateMillis);
if (lastLaunchedDateMillis != -1) {
int secsElapsed = Seconds.secondsBetween(lastLaunchedDate, current).getSeconds();
Log.e("VI PRINT", "HomeActivity.onCreate " + "secsElapsed:" + secsElapsed);
} else {
VITPreferencesUtils.saveLongGeneric(PuzzleApp.getInstance(), "first_launch_date", current.getMillis());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment