Log in

Categories » ‘HowTo’

Serialization 101 with JSON in Android

June 17th, 2012 by

JSON is a wonderful data format. It is lightweight, easy to use, and has a simple structure that closely matches data types and structures available in any full-featured programming language (implementations exist for several dozen programming languages). When i am not using libs11n for serialization, i use JSON.

This post is about getting started with JSON-based serialization in Java. What does “serialization” mean? It basically means “saving and loading,” but at a more abstract level than simply to/from files. Serialization has many uses, e.g. passing data between activities or services (e.g. GDrive or the clipboard). Why not use Java’s built-in serialization? It is fine for RPC and other forms of transient data, but its format is not guaranteed to stay stable across invocations, and is therefore completely unsuited for use in storing application data longer-term.

Grokking the ListAdapter, Part 1 of N

June 15th, 2012 by

Here’s my first published tip regarding Android development…

i admit it – my first 4 or 5 days with Android i simply could not understand how to use the ListView and the related Adapter classes. i kept having to add 1 or 2 levels of containers between my data and the list view, and kept thinking, “certainly this is not intended to be so painful!” Finally, after hours of reading through example after example demonstrating SimpleAdapter and friends, i came across a comment post somewhere (now lost) which demonstrated a very simple anonymous subclass of ┬áBaseAdapter (far simpler than the jumping-through-hoops demonstrated by most examples i had seen). The following demonstrates a real live function (not a contrived example) which demonstrates how to use the ListAdapter: