Escaping % in ICS Preferences - Do I really have to write version specific string handling?

Viewed 470

I have an app that crashes on ICS. Worked fine up to then (though I'm not sure if I ever really got a honeycomb platform to test on, all of our test phones are either gingerbread or lower, and now I have a couple ICS phones to play with).

The following code (called from onResume and OnPreferenceChangeListener) from my preferences page has worked fine:

protected void setBatteryAlarmSummary(String newValue){
    Preference batteryAlarm = (Preference) findPreference( getString(R.string.battery_low_alarm) );
    StringBuilder summary = new StringBuilder();
    summary.append(getString(R.string.battery_alarm_summary_label));
    summary.append(" ");
    summary.append(newValue);
    summary.append("%");
    batteryAlarm.setSummary(summary);
}

This sets the pref summary to "Low Battery Alarm at 10%". Now, with ICS, it crashes. Not when it does the setSummary, and not when the page displays, but when you scroll the preferences even a little bit, obviously triggering a render (this item is about 8 or so items down, so it's "below the fold" on the list). Fixing ICS is easy, just escape the percent sign:

summary.append("%%");

However, that code on gingerbread displays "Low Battery Alarm at 10%%"

I can write it to change based on version, but that's just silly. Did they really break backward compatibility on their preferences rendering, or is this just a Samsung thing (which, unfortunately, is the only test platform I have for ICS right now)?

2 Answers
Related