Use this function in the onCreate handler:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... if (isFirstTime()) { // show dialog } ... } /*** * Checks that application runs first time and write flag at SharedPreferences * @return true if 1st time */ private boolean isFirstTime() { SharedPreferences preferences = getPreferences(MODE_PRIVATE); boolean ranBefore = preferences.getBoolean("RanBefore", false); if (!ranBefore) { // first time SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean("RanBefore", true); editor.commit(); } return !ranBefore; }
Note : this requires permission to access the file on the repository: android.permission.WRITE_EXTERNAL_STORAGE
source share