Skip to content

Instantly share code, notes, and snippets.

@mtsahakis
Created March 30, 2016 15:13
Show Gist options
  • Save mtsahakis/a8b8a65dc4f5af1cb115fe1ccf09ce5b to your computer and use it in GitHub Desktop.
Save mtsahakis/a8b8a65dc4f5af1cb115fe1ccf09ce5b to your computer and use it in GitHub Desktop.
A simple utility class that checks whether an app is started for the first time. If so, it sets a boolean shared preferences value accordingly.
import android.content.Context;
import android.preference.PreferenceManager;
public class QueryPreferences {
private static final String sIsFirstRun = "IS_FIRST_RUN";
public static boolean isFirstRun(Context context) {
boolean result = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(sIsFirstRun, true);
if(result) {
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(sIsFirstRun, false).apply();
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment