As Android application developer sometimes when we release a new version of our application, we want to provide information to user about what changes have been made or what features have been added into the new version. The best way is to display a ‘What’s New‘ dialog that shows information about new changes and features when the application starts after updated. This dialog should only be displayed once when application starts. If user want to open the dialog manually, we can provide it via a menu.

To display a What’s New dialog, we can compare current application version number with the previous version number. If the current version number is greater then previous, that means the application is newer or recently updated then we should display the dialog and save the current version number .
Code implementation in Android:
public class MainActivity extends Activity {
private static final String PRIVATE_PREF = "myapp";
private static final String VERSION_KEY = "version_number";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init() {
SharedPreferences sharedPref = getSharedPreferences(PRIVATE_PREF, Context.MODE_PRIVATE);
int currentVersionNumber = 0;
int savedVersionNumber = sharedPref.getInt(VERSION_KEY, 0);
try {
PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0);
currentVersionNumber = pi.versionCode;
} catch (Exception e) {}
if (currentVersionNumber > savedVersionNumber) {
showWhatsNewDialog();
Editor editor = sharedPref.edit();
editor.putInt(VERSION_KEY, currentVersionNumber);
editor.commit();
}
}
private void showWhatsNewDialog() {
LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.dialog_whatsnew, null);
Builder builder = new AlertDialog.Builder(this);
builder.setView(view).setTitle("Whats New")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
}
Look at init() method (line 14):
try {
PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0);
currentVersionNumber = pi.versionCode;
} catch (Exception e) {}
int savedVersionNumber = sharedPref.getInt(VERSION_KEY, 0);
if (currentVersionNumber > savedVersionNumber) {
showWhatsNewDialog();
Editor editor = sharedPref.edit();
editor.putInt(VERSION_KEY, currentVersionNumber);
editor.commit();
}
Related post: