Android Development & Technology
  • Serializing Data - JSON vs. Protocol Buffers

    JSON and Protocol Buffers are two methods for serializing data, primarily used for lightweight server-client and inter-server communication. In this post we are having a look at the performance of the latest Protocol Buffers (version 2.2.0) compared to JSON, using Java on a G1 Android phone and Python with CJSON and SimpleJSON on a typical Linux system.

    • JSON serializes data using UTF-8 / 16 / 32 encoding, with turn-key libraries for most programming languages. Any data structure can be serialized with JSON, although binary data (such as an image) has to be encoded with an algorithm like Base64 before.
    • Protocol Buffers is an open-source project developed by Google and released under the BSD license. It uses a binary encoding which makes the serialized data a bit smaller and does not require binary data to be encoded before. The data-structures have to be described before serialization by creating a .proto file, compiling it with protoc and including the header files in the project. The libraries from Google are available for Java, Python and C++, with third party implementations for most other programming languages.

    For the performance tests we imagine a news aggregator application, which requests 10 news items from a server. Each item has the following data structure (using around 2.3 kilobytes with an 48×48px image):

        class NewsItem {
            String title;
            String text;
            String link;
            byte[] image; /* 48x48px */
        }
    

    The app could be faster by receiving just the infos in a first request and the images in a second, but to compare the serialization speed of JSON and Protocol Buffers we use one combined response (JSON: 23.6kb with base64 encoded images, PB: 18.3kb due to binary encoding).

    1. Library Size

    Let’s start with having a look at the different libraries and their size in kilobytes:

    Protocol Buffers isn’t the smallest library which might not matter on many systems. Using it in an Android app would often 5 to 10-fold the application size, whereas JSON is integrated in the Android stack by default.

    2. Serialization Performance - Python

    The following chart portrays the (de-)serialization time for one request with 10 news items, measured in 1.000.000 runs on a typical Linux system: Read the rest of this entry »

  • 2D Physics on Android (using Box2D)

    This post is a brief tutorial on getting started with 2D physics on Android.

    2D physics can greatly enrich games by realistic behavior of objects such as polygons (boxes, rectangles, polys) and circles in a world setting. The engine calculates collisions, angles, forces and momentums based on user-defined settings such as gravity, density, friction, elasticity, etc.
    Read the rest of this entry »

  • Using Threads and Handlers to make non-blocking web-requests

    Here is a piece i’ve come across recently on Android: If you use a Handler to make a web-request (load the html of an url into a string), it will block the app. The proper way to do that is with Threads. Threads cannot interact with the GUI though, so they need to call a Handler which can do that. Using this method it’s easy to download files in the background without blocking or annoying the user.
    Read the rest of this entry »

  • Iconic Memory v1.2.0

    Today we released version 1.2.0 of Iconic Memory, that will improve gameplay a lot, especially for better players!

    Due to a bug, after lvl60, the levels got a lot easier again. To make it fair, we will be removing all high-score entries > lv60 to give everyone a new, fair chance!

    Read the rest of this entry »

  • Developing and publishing an android game in like three days

    Iconic Memory is a fast paced puzzle/memory game using androids touch-screen, a project a friend of me and I have been working on (video). This was our first game for android and we went through the whole idea–design-development-release process in just about 3 days.

    After smoothing out the last rough spots late yesterday, we released the game on Android Market at around 2am. In the first 10 hours the game was already downloaded 500 times! We are very happy about the positive feedback and ratings we received, and want to encourage anyone thinking about starting a small project like this. It’s a great opportunity to get an understanding of the ins and outs of the whole process. And there is no formal review, thus every submitted app appears in the market and will be rated by android users!
    Read the rest of this entry »

  • Android Development — Basic Setup in 2 Minutes

    This is a mini-crash-course for setting up a development environment for Android in less than 3 minutes (given you’ve got broadband). And there are no installations required, just download and extract.

    What do you need?

    • Internet access
    • A running Linux, OSX or Windows

    Let’s get started!
    Read the rest of this entry »

imprint