Android development primer: Android Virtual Devices

In my last post, I showed you how to set up Android SDK using either ADT Bundle or SDK Tools in your system. So technically you have all the pieces of the puzzle you require, in order to start off creating Android Applications. But, before you get into any real time application programming you need to familiarize yourself with AVDs or Android Virtual Devices.

WHAT ARE ANDROID VIRTUAL DEVICES?

Android Virtual Devices or Emulators as you will come to call them, are virtual devices that install in your system and emulate an Android device. An AVD can emulate most, but not all functionalities of an actual Android device. It is more than sufficient for our development needs.

WHY DO WE NEED ANDROID VIRTUAL DEVICES?

Any sort of development process is a continuous sequence of coding and debugging. If you have any prior knowledge of programming of any kind, you know that when a program executes it goes through an Input-Output sequence. However, here we will not be requiring the traditional form of outputs that usually appear on the terminal window of an IDE. Since we are creating applications for real world devices, we need to know exactly what our code creates and how it behaves on an Android device. Not every developer out there possesses an Android device and even for those who do, it is not practically possible to install the application every time a minor/major change has been made to it. It is during this time that AVDs come to the rescue. With every change you make in your application you can execute it on the emulator to see how it will be reflected in a real-time Android device.

Remember that nothing comes even close to testing your application on a real device because emulators are rather slow. But for relatively unimportant changes emulators do a pretty good job. I recommend trying the application on a real device at regular intervals or when major changes/updates/functionality additions are done.

SETTING UP AN ANDROID VIRTUAL DEVICE

Depending on the version of the SDK/AVD Manager you are using, certain options may or may not be available. Setting up an Android Virtual Device is fairly straight-forward. Follow the steps below:

  • Launch the AVD Manager by clicking on the AVD Manager.exe file in the sdk folder. You can also launch it from within Eclipse, by clicking Window -> Android Virtual Device Manager
  • Click the New button on the top right.
  • Provide an AVD Name of your choice.
  • From the Device drop down menu choose a suitable device.
  • Target is the version of Android you want this device to have. Remember that the drop down menu will display only those versions whose APIs you have installed.
  • CPU/ABI is automatically selected for you.
  • Set up your specifications for Front Camera/Back Camera/RAM/Internal Storage/SD Card. As I said earlier, an AVD can emulate most features of an actual Android device. It includes Internal Storage and External SD Card.
  • You will find a Snapshot check box. With snapshot enabled, whenever an AVD is launched it launches from a snapshot of it’s previous run. Although this will take a relatively longer time while closing, it’s startup time decreases incredibly. I would recommend enabling snapshot.
  • The Skin option helps with creating emulators with various resolutions and screen sizes. You’re gonna want to come here and create a bunch of AVDs when you are testing your application against devices with different screen resolutions.
  • You can check/uncheck Use Host GPU option according to your needs.
  • If all the data that you entered is acceptable, you can now go ahead and create the AVD.

Once created, the AVD should be displayed in the AVD Manager with little icon to the left of it’s name that shows it’s status. The bottom of the AVD Manager shows what these mean. If you face problems with you AVD, you can always delete the AVD and create a new one.

LAUNCHING AN ANDROID VIRTUAL DEVICE

Select the emulator you just created and click “Start”. The start dialog has a few options, all of which are explained below:

  • Skin – This shows the screen resolution of the chosen AVD.
  • Density – This shows the density of the pixels of the AVD screen.
  • Scale display to real size – This option is enabled if the resolution of the AVD is bigger than your screen. You can scale it down and enter the AVD screen size and the Scale below changes automatically.
  • Wipe user data – It emulates the “Reset Factory Settings” function of an Android device. It is generally enabled when after installing a bunch of applications and changing settings to fit your needs, you need to reset them and uninstall all the applications.
  • Launch from snapshot – This option can be enabled only if “snapshot” was enabled during the creation of the AVD. It launches the AVD from a snapshot of it’s previous run.
  • Save to snapshot – This option can be enabled only if “snapshot” was enabled during the creation of the AVD. It saves a snapshot of the current run of the AVD so that it can be launched from the exact same place next time.
  • Click Launch.

Now, it will take some time for the first launch. Subsequent launches will be faster if “snapshot” was enabled.

Note :- If you possess an Android device, it is apparent that the AVD launch is different from your device’s start up. This is because the factory settings of actual Android devices include extra layers of UI (User Interface) giving them fancy start-up animations and sounds. These differ across devices from different companies even if the Android version is same. The AVD however does not possesses any such layers and shows the primitive form of the selected Android version.

Leave a Comment

Your email address will not be published. Required fields are marked *