Running Android applications
When it comes to running Android applications, we get to choose between using a real device (phone or tablet) and an emulator Android Virtual Device (AVD) as the target. Both have their advantages and drawbacks. While Android devices offer the complete experience at full speed, their disadvantages include the following:
- Slower to start. Loading an application onto an AVD is generally faster, decreasing debugging times.
- Limited access, with the root account unavailable on Android devices unless you enable it in the firmware. Full access to the device's filesystem is disabled, including application data.
AVDs do not have these disadvantages, but they have the following limitations:
- They are slow: Even when using the Intel Atom images and having Intel's HAXM virtualization add-on installed, any device handily beats an AVD
- Lack of OpenGL ES support: While OpenGL ES support is experimentally being added, it's still unstable and, of course, so slow that it is unsuitable for any serious application
- Lack of microphone support: At the time of writing this book, it's not possible to use a system microphone with an AVD
- No motion sensors: We can only test portrait and landscape modes
- No light sensor or LED:
- No compass, GPS, and so on: These can be faked, however, by setting GPS coordinates in the AVD
Beyond these differences, devices and AVDs are quite similar. Which one to use depends largely on your needs. However, any verification and non-simple debugging should, as a rule of thumb, always be done on a device. While an AVD approaches the functionality of a real device, it is still so different and limited that its results should not be relied upon as real device behavior.
That said, both can be used in an identical fashion with ADB, or the Android Debug Bridge. ADB is a client-server program that consists of a server running on the Android device or AVD, and a client running on the system accessing it. The ADB client can either be run as a command-line tool or be used from within an IDE such as Eclipse for purposes such as uploading applications to the Android device or AVD, uploading and downloading files, and viewing system and application logs in real time.
Especially the ability to view logs in real time for any running application is very helpful to us when we try to debug an application, as we can output any debug messages to the log.