Android Tips Round-Up, Part 1

With my recent project I've been posting one Android class/method a day. People have been asking for an archive of these links, so every couple weeks I'm going to round them up here. I'll also be adding a bit of color commentary, but still the goal is for this not to be a ton of work for me. :)

More: Part 1 | Part 2 | Part 3 | Part 4 | Part 5

Activity.startActivities() - Nice for launching to the middle of an app flow.

TextUtils.isEmpty() - Simple utility I use everywhere.

Html.fromHtml() - Quick method for formatting Html. It's not particularly fast so I wouldn't use it constantly (e.g., don't use it just to bold part of a string - construct the Spannable manually instead), but it's fine for rendering text obtained from the web.

TextView.setError() - Nice UI when validating user input.

Build.VERSION_CODES - Not only is it handy for routing code, it's also summarizes behavioral differences between each version of Android.

Log.getStackTraceString() - Convenience utility for logging.

LayoutInflater.from() - Wraps the long-winded getSystemService() call in a simple utility.

ViewConfiguration.getScaledTouchSlop() - Using the values provided in ViewConfiguration ensures all touch interaction feels consistent across the OS.

PhoneNumberUtils.convertKeypadLettersToDigits - Makes handling phone number data a snap, as some companies provide them as letters.

Context.getCacheDir() - Use the cache dir for caching data. Simple enough but some don't know it exists.

ArgbEvaluator - Transition from one color to another. As was pointed out by Chris Banes, this class creates a lot of autoboxing churn so it'd be better to just rip out the logic and run it yourself.

ContextThemeWrapper - Nice class for changing the theme of a Context on the fly.

Space - Lightweight View which skips drawing. Great for any situation that might require a placeholder.

ValueAnimator.reverse() - I love this for canceling animations smoothly.

comments powered by Disqus