Displaying a changelog

The new (upcoming) 1.7 release of Wifi Manager has a few new features, so I’ve set out to add a changelog. I wanted the changelog to be displayed automatically just once whenever a new version is run for the first time.

Creating the activity to display the change is not too difficult. I wanted the actual changelog to be stored as a file packaged within the application, so I put the change log into res/raw/changelog.txt and res/raw-ru/changelog.txt (for Russian locale).

The code is necessary to translate Windows style newlines into Java (Unix) style newlines. I could be more careful with creating the change log resource, but this way it works with whatever type of newlines is used in the changelog.

As you can infer from the above, raw resources get their own resource IDs (R.id.blah), and can be accessed with openRawResource.

In my application’s main activity, I have code to determine the version code (as specified in the manifest) of my application, and compare it with the value persistently stored in a SharedPrefernce:

The mSettings above is a simple wrapper around SharedPreferences that loads and stores settings and keeps them around as member variables.

But what is this part: mHandler.post(mShowChangeLogTask)?

I wanted to start the changelog activity with startActivityForResult, so that it has more of a “modal” feel to it. However, there was a problem: since I the code above is contained in onStart(), immediately invoking another activity caused the main activity to not redraw until after the user closes the change log activity. This looked pretty ugly. To avoid this problem, I made sure that Android finishes redrawing the main activity before launching the changelog activity.

The code above fixes the problem – by allowing the main activity to redraw before the changelog activity is displayed.

Finally, to make sure that the changelog is displayed just once for each new version code, I added code in the main activity’s onPause to save the updated “last known” version code (mSettings.mOldVersionCode) to shared preferences.