The wonders of Android development

Tags: android, java, bugs

Recently I've been doing some Android development. I remember that in the Dark Ages of Android 1.1 (TM) there were many annoying things, but I survived that somehow and forgot about them.

This will be little rant on Android, so if you are Android fanboy, then, well, you'd better go watch some kittens on youtube. Or you can hate me in the comments below.

Years have passed, Android now is in version 6.0 or 7.0, but some things just don't change. There are still few very and annoying bugs in Android that I stumbled upon.

1. Localized numberDecimal EditText

Imagine an app with the field where you need to input some decimal value, like pressure in your car's tires. You want to enter value 2,32 bar (or PSI, doesn't matter). So you tap on a field and this is what'll see:

Missing something? That's right, there's no comma. No freaking comma. And when your culture has comma as decimal separator, then, well, you're out of luck because probably in Activity that's behind this layout is something like this (which is ok by the way):

NumberFormat nf = NumberFormat.getInstance(Locale.getDefault());
float ctrlVal = nf.parse(ctrl.getText().toString()).floatValue();

Parsing won't succeed so you'll get validation error. I must say, that when I run into this issue, I couldn't believe it and I thought maybe I was doing something wrong. But then I found that this is a bug dated to... 2009 and Android 1.1 with priority Medium. I wonder how old the bugs with priority Low are?

Anyway, there's some sort of workaround for this issue. You need do specify that this EditText inputType is text|numberDecimal. Then you'll get some sort of consolation prize:


tap the .-( button
(BTW it looks like half-sad emoji)

There it is! There's our missing comma!

2. TimePickerDialog.OnTimeSetListener gets called twice

This is also very funny issue. When you use TimePickerDialog (or DatePickerDialog) then you provide a callback/listener TimePickerDialog.OnTimeSetListener (or DatePickerDialog.OnDateSetListener). Now, when the user selects time or date in this picker, you'll have onTimeSet (or onDateSet) method called. But you'll have it called TWICE. Yes, TWICE. I have not idea why, but it's just the way it is.

Of course there's a workaround for this: you need to set tag on a picker like this:

@Override
public void onTimeSet(TimePicker timePicker, int hour, int minute) {
    if (timePicker.getTag() == null) {
        timePicker.setTag("TAGGED");
        // Here were are only once per Dialog
    }
}

The SO question is from 2013, but I'm not sure when it was reported.

3. Date class

That's not entirely Android's fault that Date class is totally messed up, because it's just Java. But hey, I just couldn't resist putting it here on my list of Android's Wonders.

Bonus

The oldest still opened bug in Android is... the one I described in point 1 apparently. There are some other issues from 2008/2009 but they're not really bugs, but rather enhancements.

Ok, as the closing note and to be totally fair, Android isn't that bad. There are worse.

Comments