Is there on install event in android?

前端 未结 4 622
余生分开走
余生分开走 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();
    
    0 讨论(0)
  • 2020-11-28 10:46

    I don't think there is such a thing, and I don't think this would be a good idea : usually you have to handle not only installations but some updates (say : a new version with features) or the proper initialization of some resources.

    For the resources, the best way is to check them directly.

    For the version, I use the database, it's so easy.

    0 讨论(0)
  • 2020-11-28 10:56

    The SQLiteOpenHelper's OnUpgrade method is called when the database version changed. I suppose this could be used to do other things than just handling the new schema.

    0 讨论(0)
  • 2020-11-28 11:09

    See Get referrer after installing app from Android Market - you can put whatever you want in there. I believe this is how Plan B works - the app that can send back your phone's location after it's stolen, that you install from the website after it's been stolen.

    0 讨论(0)
提交回复
热议问题