I want to show a message after the first launch of the app telling about the new features, each time开发者_运维百科 a user installs a new version.
How do I do that?
Thanks in advance
I used this. It was posted by another stackoverflow member I don't recall who. Sorry. Call this code from onCreate()
// Show changelog
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
PackageInfo pInfo;
try {
pInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
if (prefs.getLong("lastRunVersionCode", 0) < pInfo.versionCode) {
showDialog(DIALOG_CHANGELOG);
SharedPreferences.Editor editor = prefs.edit();
editor.putLong("lastRunVersionCode", pInfo.versionCode);
editor.commit();
}
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Error reading versionCode");
e.printStackTrace();
}
Have an activity for this, that checks if a preference has the value of the current version. If so proceed to the next activity. Otherwise störe the current version in the preference, show the what's new screen and then on button press procees to the next activity
That's simple. On the first start show an AlertDialog and create a record in SharedPreferences. Whatever - flag or a string, or somewhat. The next time your application is started just check that you have this flag in preferences. If there is no one, then this is a first start and it's time to show a dialog =)
You have to save somewhere a value which you can check on each startup whether the app was already started. SharePreferences would be a option. Or within a database.
if the user clears application data in the device settings then this all gets reset.
精彩评论