Slide 8
Slide 8 text
public static boolean hasStartedFromLauncher(Context context) {
return context.getSharedPreferences(SHARED_PREFS_NAME, 0)
.getBoolean(KEY_STARTED_FROM_LAUNCHER, false);
}
public static void onActivityCreate(Activity activity) {
final SharedPreferences sp = activity.getSharedPreferences(SHARED_PREFS_NAME,
0);
if (sp.getBoolean(KEY_STARTED_FROM_LAUNCHER, false)) {
return;
}
final Intent launchIntent = activity.getIntent();
if (launchIntent == null) {
return;
}
if (Intent.ACTION_MAIN.equals(launchIntent.getAction())
&& (launchIntent.hasCategory(Intent.CATEGORY_LAUNCHER)
|| launchIntent.hasCategory(IntentCompat.CATEGORY_LEANBACK_LAUNCHER))) {
SharedPreferencesCompat.EditorCompat.getInstance().apply(
sp.edit().putBoolean(KEY_STARTED_FROM_LAUNCHER, true));
}
}
AppLaunchChecker.java