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 […]

Android – simulate application upgrade

This works on emulators or real devices. Run the app normally on the device or emulator. While it’s open, run adb install -r /path/to/that/debug.apk This will even trigger things like PACKAGE_REPLACED intents.

Android – play encrypted video in ExoPlayer

/UPDATE: the original version of this post is fine for small video files, as it decrypts the entire file and reads the clear stream into memory. For large files though this is probably not feasible; a work-around is provided. The original post is included at the end. Reference Playing encrypted video in ExoPlayer turns […]

Simple Event Bus in Java

A lightweight, simple pub-sub implementation. In Android, this class could provide much of the same functionality as LocalBroadcastManager, without the need for a Context instance. Note that while getting the instance is thread-safe, its methods are not.

Android – Detect if on UI Thread (Main Thread)

Android – Find Views / Children By Class

Common Android Tasks

Start an Activity

Start an Activity and pass data

Reading data from a bundle when starting a new Activity

Save Instance State

Restore Instance State

Asynchronous Network Request with OKHttp

Load an Image into an ImageView with Picasso

Load in Image as a Bitmap with Picasso