Skip to content

Instantly share code, notes, and snippets.

@LouisCAD
Created November 12, 2016 01:18
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 LouisCAD/7df092f7d09bec81978b0f669209a66e to your computer and use it in GitHub Desktop.
Save LouisCAD/7df092f7d09bec81978b0f669209a66e to your computer and use it in GitHub Desktop.
import android.content.Context
import android.preference.PreferenceManager
inline fun Context.runOnce(uniqueKey: String, f: () -> Unit) {
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
val isFirstRun = prefs.getBoolean(uniqueKey, true)
if (isFirstRun) {
prefs.edit().putBoolean(uniqueKey, false).commit()
f()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment