The retained fragment trick

The first tough problem a new Android developer faces is how to manage work in the background. Spawning a new Thread is easy, but once UI objects need to be notified with the result, the situation becomes tricky: the UI objects might have been replaced by the system because of a configuration change. In this post we explore how to bind and rebind to the new UI objects with a retained Fragment. Continue reading

Espresso: Click on last item in AdapterView

In Espresso is quite easy to tap on the first element of an `AdapterView`, such as a `ListView`. This can be easily done calling `DataIteraction.atPosition(0)`. Clicking on the last item though, is much more complicated. The last position is unknown to Espresso and extracting it stringing together a `findViewById()` and `AdapterView.getCount()` seems to defeat the purpose of using Espresso altogether. Continue reading

ADB over wifi

The adb command is well known to Android developers, it provides utility commands such as shelling into a device, manipulating basic services like the activity manager, and pushing or pulling files from a device. What is not widely known is that you don’t actually need an usb cable to talk to your device. Continue reading

Getting annotation value of an enum constant

In this post we will see how to extract the annotation value, (i.e. `”choc”` in `@SerializedName(“choc”)`) given an annotated enum constant. This technique is useful when we generate strings for unit tests in the context of Json deserialization. Furthermore, we will discuss some features of enums and annotations, and their connections with the reflection API. Continue reading

The basics of bit manipulation

Talking with fellow developers, I realized that many feel confused when it comes down to bit manipulation. It is indeed something not used on a day-to-day basis, but nevertheless the Android framework relies on it heavily in for memory optimizations: when a boolean can do, a bit can do too. Examples are View and Window flags. This post sets out to demystify the basics of bit manipulation: afterwards it will feel no more difficult than using arrays. Continue reading