Is there on install event in android?

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();

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.


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.


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.