Monday, June 20, 2011

The Android Cloud to Device Messaging Framework


JSON vs XML


It depends on what type of client will be connecting to that web service.

If you plan to contact the web service from inside a browser a'la AJAX calls from Javascript, then JSON is the hands-down winner because it essentially is the serialization of Javascript objects. This property of JSON makes it a much better fit for client-side scripting in Javascript. JSON data can be regurgitated right into living, breathing Javascript objects without much hullabaloo.

XML and JSON were designed for two distinct purposes. XML originated as a way to give semantic definition to text in documents. JSON on the other hand is specifically for serializing data structures.

Both can do what each other can do, but those fundamentally different base design rationales are I think evident in how you work with each type of markup.

True, XML can represent data structures, but an example of describing structures like empty arrays in XML shows off how JSON is much better at describing data structures.

JSON on the other hand is woefully mismatched to describe semantic meaning behind text in documents, which is where XML excels (think HTML).

No easy answer. The requirements of your connection client and the type of data you need to serialize should drive the decision between XML and JSON.

JSON for web services answering in-browser callbacks, and XML for, well, XML for when, well.

Wednesday, June 15, 2011

Android - NDK

NDK allows you to develop parts of your Android application in C/C++.
You cannot develop native-only apps in NDK – your app is still subject to security sandboxing.
Main motivation for native code is performance.


  Using NDK





Android - Building and Running JNI Code


Android Application Runtime Native Daemon Library


Android Application Native Service Lib


Android Application Runtime Service Lib


Android Runtime Overview


Android Startup


Android Application Security

Each Android application runs inside its own Linux process.

Additionally, each application has its own sandbox file system with its own set of preferences and its own database.

Other applications cannot access any of its data, unless it is explicitly shared.



Android Application Framework

Activation manager controls the life cycle of the app

Content providers encapsulate data that is shared (e.g. contacts)

Resource manager manages everything that is not the code

Location manager figures out the location of the phone (GPS, GSM, WiFi)

Notification manager for events such as arriving messages, appointments, etc

Android and Java

Android Java = Java SE – AWT/Swing + Android API

Dalvik Virtual Machine

Dalvik VM is Google’s implementation of Java Optimized for mobile devices

Key Dalvik differences:
Register-based versus stack-based VM
Dalvik runs .dex files
More efficient and compact implementation
Different set of Java libraries than SDK

Android Native Libraries

Bionic, a super fast and small license-friendly libc library optimized for embedded use.

Surface Manager for composing window manager with off-screen buffering.

2D and 3D graphics hardware support or software simulation.

Media codecs offer support for major audio/video codecs.

SQLite database.

WebKit library for fast HTML rendering.

Linux Kernel


Android runs on Linux.

Linux provides as well as:
     Hardware abstraction layer
     Memory management
     Process management
     Networking
     Users never see Linux sub system

The adb shell command opens Linux shell

Android Stack


Android Architecture


Thursday, June 2, 2011

Five tips for saving battery life on an Android phone

1. Shut off unnecessary services

I have found the GPS does little to get me through the day. So unless I am using an application that absolutely must have the GPS turned on (and it’s an app that I must use), I leave that feature turned off. It can drain the battery the fastest, so when you need battery life over location discovery, turn it off and leave it off. Turn off WiFi as well. It’s another top offender. Although many might argue against this, I find the speed gain of WiFi is not significant enough to offset the battery drain.

2. Upgrade your firmwar

You would be surprised how much better 2.x is at retaining battery life than is 1.x. It was a significant upgrade on many levels, but none was more significant than battery life. One of the critical issues that was fixed was the ever-present messages application not going to sleep. Now the tool goes to sleep, thus saving your battery from an untimely demise.

3. Turn off notifications

Believe it or not, notifications can seriously drain your juice. I like to leave on notifications for text messages but no more. Turn off both sound notifications and LED notifications to save as much battery as you can. Just remember that you will have to manually check your email to see if anything is new since the last time you checked. Common sense, but you never know.

4. Turn off keyboard feedback

This one may not seem so obvious to most users, but that vibration does use power. As often as you use your keyboard, you’re adding to the decline of your battery power click by click by click. This actually serves two purposes. With the feedback turned off, your keyboard will also respond much faster than it would with it on.

5. Add a task killer

I like Advanced Task Killer Free. This tool allows you to kill any task that is currently running. I actually place a shortcut to this tool on my desktop so that a single press will kill any unnecessary tasks that are slowly chomping away at my battery life. I will randomly hit this during the day (especially when I feel my phone heating up) to kill those background apps. I have yet to experience an app like this taking the phone down with it, so you can generally feel pretty safe using such tools. And the battery life they will save is certainly worth the price of admission (even the non-free apps).



Android tips and tricks

Use voice activation

 

If you’re walking down the street and need to send a text message, you can use the voice activation feature to instruct your Android phone what to do. This is a much better option than potentially falling headfirst into an open manhole or crashing into a pole and winding up on YouTube, only to become the laughingstock of your company and friends. To use voice activation, long press the Search button on the handset (it looks like a magnifying glass) and then speak into the phone. It is also possible to use the voice activation for various purposes, which include the following:
  • Text: send text to [recipient] [message] example: send text to stephanie meet me for burritos after work
  • Email: send email to [recipient] [subject] [body] example: send email to jack wallen reminder don’t forget to pick up pizza
  • Directions: navigate to [location] example: navigate to bazos
  • Place phone call: call [contact] [phone type] call stephanie mobile
  • Listen to music: listen to [artist/song/album] example: listen to rush tom sawyer moving pictures
  • Write note: note to self [note] example: note to self found model for among you book cover
  • Search Google: [query] example: jack wallen books
  • Open website: go to [website] example: go to amazon
  • View a map: map of [location] example: map of munich