Android – View traversal / walker / finder utilities

Android – LinearLayout with dividers (separators)

Add (or amend) your values/attrs.xml to include:

Some layout:

And the class:

Android – launch modes and multiple intents

The behavior here isn’t quite what I expected, or gather from the documentation. If you have <activity android:name=”.SomeActivity” android:launchMode=”singleTop” /> Then you start SomeActivity multiple times:

You’ll get only one instance of SomeActivity at the top of the stack (as the singleTop launch mode promises), but you’ll notice that if you finish() or hit […]

Android – get default text size

Possibly useful in precomputing layout requirements…

Java – Unexpected Bounds when extending a typed Class

When extending a typed class without specifying the type, just pass the type to the subclass’s erasure and specify that type in the reference to the superclass. E.g.,

As an example, consider the AOSP class RecyclerView.Adapter, which is declared as:

A normal concrete implementation is fairly straightforward:

But what if you want […]

Java – Super Class constructor fired before SubClass members are initialized

Probably unexpected behavior:

There’s not a direct way to work around this – often initialization or setup methods are used, sometimes with a Factory instance generator.

Android – SteakKnife – simple ViewBinding with annotations

Butterknife, like most things by Square and/or Jake Wharton, is a very handy, very popular library. One thing that was really nice was how small and simple it was. The latest version, however, is a lot less simple, and requires multiple gradle dependencies and the apt plugin. Not a huge lift, but not exactly as […]

Android – get removable SD card location

This is a little tricky, and isn’t precisely a version limitation. Here’s why, and how I’ve found the most reliable way to get it. 1. Environment.isExternalStorageRemovable (without parameters) is API 9+, so has broad support. If your devices primary external storage location is removable, then this will return the location you want – done. 2. […]

Android – RecyclerView with smooth infinite / endless scroll

/EDIT: I’ve created a library (and demo): Most “endless” RecyclerViews wait until the last item is visible, then load more data, which is often fine and probably very more efficient strategy. However, sometimes we need to be a little more responsive, and try not to let the scroll come to a complete stop. Here’s […]

Android – write to or copy file

There are several approaches to this in Java generally and Android specifically. At this point, I almost exclusively use InputStreams and OutputStreams, with chunks appropriate to the size of the data I’m dealing with (e.g., I’ll use 1mb chunks when dealing with large video downloads, or 1kb chunks for small images, or even no chunks […]