Is there on install event in android?

前端 未结 4 645
余生分开走
余生分开走 2020-11-28 10:18

Is there some event/receiver or something for handling first execution after installation or directly after installation? Or Do I need it emulate with preferences?

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 10:45

    There is the ACTION_PACKAGE_ADDED Broadcast Intent, but the application being installed doesn't receive this.

    So checking if a preference is set is probably the easiest solution.

    SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this);
    boolean firstRun = p.getBoolean(PREFERENCE_FIRST_RUN, true);
    p.edit().putBoolean(PREFERENCE_FIRST_RUN, false).commit();
    

提交回复
热议问题