Parcels and inheritance in Android

To pass information between Activities and save states during the application lifecycle, Android uses Parcel objects. Like Serializable in Java, the Parcelable interface offers a marshalling mechanism to represent and transfer object instances as bytes. In this post I will present some of the differences between Parcels and Serializable, then explain how to implement the Parcelable interface correctly, in particular in a hierarchy of inherited classes. Why Parcel? Parcels are a lightweight alternative to Serializable for inter-process communication. As stated in the documentation, it is not a general purpose serialization mechanism and should not be used to store object representations…

read more...

A try-with-resources equivalent for Java 6 and Android

In Java core libraries, resources such as network, files and databases can be accessed through a large range of low-level interfaces which all require to explicitly handle exceptions and release resources properly. As a consequence, writing such code is arguably more error-prone than in languages with high-level resource access methods, and it is actually quite common to find bugs related to flawed resource management in Java codebases. To tackle this issue, Java 7 offers higher-level methods to access files in the java.nio.file package, but also a new try-with-resources language construct to automatically release resources, even when errors occur.…

read more...

Android Studio 2.0 is out

Google released the second version of the official Android IDE a few days ago and it looked like a good incentive to get back to some Android programming! I took a few hours last weekend to update my SDK and give a try to this new shiny environment. New features This release is based on IntelliJ 15, and beyond the new features shipped in that version, Android Studio 2.0 brings the following improvements. Instant Run This is the new big thing. In order to reduce overhead in the edit - build - run cycle, source code changes are now…

read more...

Hello World!

After many years of hacking WordPress, I wanted to move to something lighter, faster and simpler. While looking for alternatives, I found out about Ghost and immediately wanted to give it a try. Ghost Ghost is a lightweight blogging system written in Node.js, Ember.js and HandleBars. It provides a clean and simple client interface and focuses on content. The installation is easy enough if you have root privileges on your server and you know a thing or two about Unix: it boils down to installing Node.js, deploying a packaged Node project, changing two flags and setting up…

read more...