Home > android, ui > Displaying a changelog

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 to display the contents of the change log looks like this:

	TextView textChangeLog = (TextView) findViewById(R.id.change_log);

	Resources resources = getResources();
	InputStream stream = resources.openRawResource(R.raw.changelog);

	try {
		InputStreamReader reader = new InputStreamReader(stream, "UTF-8");
		try {
			BufferedReader bufReader = new BufferedReader(reader);
			StringBuilder sb = new StringBuilder();
			String s;
			while ((s = bufReader.readLine()) != null) {
		} catch (IOException x) {
		} finally {
			try {
			} catch (IOException x) {
	} catch (UnsupportedEncodingException x) {

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:

// Somewhere in onStart():

	PackageManager packageManager = getPackageManager();
	String packageName = getPackageName();
	PackageInfo packageInfo;

	try {
		packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_META_DATA);

		int versionCode = packageInfo.versionCode;
		if (versionCode != mSettings.mOldVersionCode) {
			mSettings.mOldVersionCode = versionCode;
	} catch (NameNotFoundException x) {

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.

// in main activity:

	private Handler mHandler = new Handler();
	private Runnable mShowChangeLogTask = new Runnable() {
		public void run() {
			Intent intent = new Intent(WifiControlActivity.this, ChangeLogActivity.class);
			startActivityForResult(intent, Util.REQUEST_CHANGELOG);

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.

Categories: android, ui
  1. hmm
    October 17, 2010 at 3:24 am

    So. What’s changed? Please add this info on your update page so ppl cab decide to update or. Not.

    • Kostya Vasilyev
      October 17, 2010 at 10:59 pm

      Android Market restricts application description to 325 characters.

      That’s waaaayyy too short, since I need to provide a descritption for new users, as well as describe (even in brief) what’s new.

      For detailed changelog, see the program page:


      or click “My Software” at the top of the page.

  2. echo4me
    October 9, 2010 at 3:39 pm

    Please add config to restrict with wifi signal strength. I want to get wifi more than 3 bars.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s