UPDATE 24-12-2012 – The code in this post is replaced by the open source library “Inscription” for more information:
Inscription library
In this post I’am going to share my code for a change log dialog.
Having a change log in your application gives the user the option to see what new features or bug fixes are done in your app history. It’s a good way to communicate your hard work done to create your app.
The change log dialog that I will be sharing parses a xml file and shows this as a nice styled html text. (See image attached to this post)
The styling is done with CSS code and can be adjusted to fit your app look. I Will explain this later in the post.
Import class
To use the change log in your app follow the following steps.
Download and unzip the following file and import the class in to your project.
ChangeLogDialog source code
String resources
The class needs a few resources, the first resources are string resources.
Just add these to your strings.xml file.
You might want to add translations to your project as well.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title_changelog">Change log</string>
<string name="changelog_close">Close</string>
</resources>
Change log XML file
The second resource you will need is a xml file with your change log.
This file should be in the following location of your project: “/res/xml/changelog.xml”
In this xml file you can use the following tags:
| changelog | This is the root tag. |
| release | You can add a release tag for every version of your app. The release tag needs to have two atributes: version – This corresponds to the android:versionName attribute in your manifest file. versioncode – This corresponds to the android:versionCode attribute in your manifest file. |
| change | This tag is a child tag of the version tag. You can have as many change tags as needed. The change tag contains the actual text that will be displayed as a change in your change log dialog. |
Here is a sample file:
<?xml version="1.0" encoding="utf-8"?> <changelog> <release version="1.2" versioncode="3"> <change>Fixed: A bug fix</change> <change>Button appearance changed</change> <change>Small layout change in the view item screen</change> </release> <release version="1.1" versioncode="2"> <change>Small layout change in the view item screen</change> <change>Minor tweaks</change> </release> </changelog>
Displaying the dialog
To invoke the change log dialog use the following code:
//Launch change log dialog ChangeLogDialog _ChangelogDialog = new ChangeLogDialog(this); _ChangelogDialog.show();
Customizing
Now you have your change log up and running.
If you want to change the look of the text within the dialog you can alter the following code in the ChangeLogDialog class. Just adjust the CSS code as needed.
//CSS style for the html
private String GetStyle() {
return
"<style type=\"text/css\">"
+ "h1 { margin-left: 0px; font-size: 12pt; }"
+ "li { margin-left: 0px; font-size: 9pt;}"
+ "ul { padding-left: 30px;}"
+ "</style>";
}

Thank you, it is a useful class!
Oh Martin,
you are great! Thanks a lot for this useful library. Now I can replace my quick and dirty solution. :)
Just one question: I want to write a short summary of the changes for each revision on the top of the li’s. Is it possible to “hack” this with styles easily.
Greetings and recognition to your Code
Felix
Sure it’s possible.
You would just have to add an attribute to the release tag with a summary.
Something like:
And make sure to parse it in the changelog code in this function:
//Parse a the release tag and return html code private String ParseReleaseTag(XmlResourceParser aXml) throws XmlPullParserException, IOException { String _Result = "<h1>Release: " + aXml.getAttributeValue(null, "version") + "</h1><ul>"; int eventType = aXml.getEventType(); while ((eventType != XmlPullParser.END_TAG) || (aXml.getName().equals("change"))) { if ((eventType == XmlPullParser.START_TAG) &&(aXml.getName().equals("change"))){ eventType = aXml.next(); _Result = _Result + "<li>" + aXml.getText() + "</li>"; } eventType = aXml.next(); } _Result = _Result + "</ul>"; return _Result; }This change should do the trick:
Note I did not test this code. But it should be clear what changes need to be made to get it working.
Hey Martin,
thank you very much! I added your Blog to my rss feed.
C# related things are welcome too. ;)
Your welcome. :)
PS: The value of the captcha input field is invisible on focus out (just tested on chrome)
Thanks for reporting that. I’ll take a look at that. It’s a new theme and might have a few issues I need to fix.
Hi Martin,
Thanks for your very nice class.
Do you have an idea about how to display the changelog only the first time the user launch the app, and not each time ? (may be in adding a boolean in settings ?)
You could save a version number in the shared preference.
Test the current version of the app against the version you saved in the shared preference, and when it does not match you show the dialog and update the preference.
This might be a nice addition for future updates to the code. I’ll keep it in mind, thanks for the suggestion.
Check out this post on how to get the current app version:
http://martin.cubeactive.com/android-top-tip-get-the-app-version-number/
Hello,
i was wondering if there’s any way to support multiple languages. In my comprehansion your library only supports one.
Regards,
Massimiliano
If correct you should be able to put a translated xml file in a separate folder like so:
xml (this is the default language folder, most likely English)
xml-de (this is your translation folder, in this case German)
The change log should get the correct translation according to the language set in the Android system.
Hello Martin,
Please add the code to run changelog only when first run app and after the release of code in AndroidManifest.xml
Thanks you.
Hi Alex,
This code has been replaced by the Inscription library.
You can get the dev branch from Github, in there you will find a what’s new dialog that shows the latest changes at start up.
I’m not sure that you correctly understand … if not difficult, give me a link
Thanks you, Martin
https://github.com/MartinvanZ/Inscription/tree/dev
There you will find the what’s new dialog. There is also a sample project to show how to use the new dialog.
Hi Martin! First of all i wanna say, Great tutorial! I am new to Android development and sometimes it can be hard to understand some other tutorials. I have used your “change log dialog” in my latest app that am working on. You can check it out at (http://bit.ly/qpinner) . Thanks!!!
Thank you.
I Would recommend to use the new Inscription library if you are not yet using it. It contains the same change log dialog but has improved code.
Good luck with your app. :)
Good Idea man, but trying Inscription library in my app I’ve noticed that it’s too slow to check if it’s the first boot (or if the app has been updated) and in case show the Whatsnew/Changelog message.
The check should be almost instantaneous. It’s just a simple check on the shared preferences. Maybe the rendering of the dialog itself is causing delay?
Does the check delay your startup or does the dialog not show at all? I’m wondering what the exact problem is you are dealing with.