Saturday, December 15, 2012

[android-developers] Android Lint Tool - Suggestions for 2 fatal problems (missed)

The Android Lint tool is very good at spotting potential errors.

But I think it missed 2 fatal problems:

1) No parent style defined for a custom style. [Flag as error]

If you create a custom style in res/values/styles.xml, and your new
style does not inherit from a standard Android theme, then your app
will crash at startup on a minority of devices. It's hard to spot
because most devices and the emulator do not crash. You will only find
out when you release your app, and receive loads of crash reports...

...But the crash log is weird and the solution is here:
http://stackoverflow.com/questions/2605999


2) Call getActionBar() without explicitly requesting the ActionBar to
show. [Flag as error]

If you do this...

protected void onCreate() {
getActionBar().setDisplayHomeAsUpEnabled(true);
}

...It will work on most devices. But a minority will crash at startup,
because they don't show the ActionBar by default, so getActionBar()
returns null. The correct way is like this:

protected void onCreate() {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().setDisplayHomeAsUpEnabled(true);
}

Please add these checks to the Android Lint tool. Thanks.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment