Android – RecyclerView with smooth infinite / endless scroll

/EDIT: I’ve created a library (and demo): https://github.com/moagrius/EndlessRecyclerView 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

Ran into this requirement recently, and despite a couple open questions on Stackoverflow and ExoPlayer’s issues page, there wasn’t much guidance. Turns out this is relatively straightforward if you’re not streaming the video (e.g., you’re playing it from a local file). The DataSource interface has 3 methods: open, close, and read. When the renderer is […]

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

[…]

Android Studio will not log certain Strings

Not sure what exactly is the determinant here, but when encrypting some basic information, I found that Logcat would consistently fail to report some lines – worse, it failed silently, just skipping the lines – for example, on a line above or below with

would work fine. Apparently certain characters were the offenders, since […]

Java (Android) – copy properties using public getters and setters

There are tons of existing classes that will do wonders with reflection, but some (many) aren’t available in Android… E.g., since java.beans.introspection requires AWT, it’s not supported. One common operation is copying properties from one object to another. Here’s an example using traditional Reflection. Copier.copy(objectToCopyFrom, objectToCopyTo); It’ll look at objectToCopyFrom, find all public getters (using […]