/** * Call this API when the launcher activity is launched.<br> * It is better to call this API in onCreate() of the launcher activity. * @param context Context */ public static void onCreate(Context context) { SharedPreferences pref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); Editor editor = pref.edit(); // If it is the first launch, save the date in shared preference. if (pref.getLong(KEY_INSTALL_DATE, 0) == 0L) { storeInstallDate(context, editor); } // Increment launch times int launchTimes = pref.getInt(KEY_LAUNCH_TIMES, 0); launchTimes++; editor.putInt(KEY_LAUNCH_TIMES, launchTimes); log("Launch times; " + launchTimes); editor.apply(); mInstallDate = new Date(pref.getLong(KEY_INSTALL_DATE, 0)); mLaunchTimes = pref.getInt(KEY_LAUNCH_TIMES, 0); mOptOut = pref.getBoolean(KEY_OPT_OUT, false); mAskLaterDate = new Date(pref.getLong(KEY_ASK_LATER_DATE, 0)); printStatus(context); }