tags:

views:

223

answers:

3

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?

A: 

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.

dystroy
+11  A: 

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();
Dave Webb
A: 

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.

cdonner