8 min read

This article written by Belén Cruz Zapata, the author of the book Android Studio Essentials, teaches us the uses of the AVD Manager tool. It introduces us to the Google Play services.

(For more resources related to this topic, see here.)

The Android Virtual Device Manager (AVD Manager) is an Android tool accessible from Android Studio to manage the Android virtual devices that will be executed in the Android emulator.

To open the AVD Manager from Android Studio, navigate to the Tools | Android | AVD Manager menu option. You can also click on the shortcut from the toolbar. The AVD Manager displays the list of the existing virtual devices. Since we have not created any virtual device, initially the list will be empty. To create our first virtual device, click on the Create Virtual Device button to open the configuration dialog. The first step is to select the hardware configuration of the virtual device. The hardware definitions are listed on the left side of the window. Select one of them, like the Nexus 5, to examine its details on the right side as shown in the following screenshot. Hardware definitions can be classified into one of these categories: Phone, Tablet, Wear or TV.

We can also configure our own hardware device definitions from the AVD Manager. We can create a new definition using the New Hardware Profile button. The Clone Device button creates a duplicate of an existing device.

Click on the New Hardware Profile button to examine the existing configuration parameters. The most important parameters that define a device are:

  • Device Name: Name of the device.
  • Screensize: Screen size in inches. This value determines the size category of the device. Type a value of 4.0 and notice how the Size value (on the right side) is normal. Now type a value of 7.0 and the Size field changes its value to large. This parameter along with the screen resolution also determines the density category.
  • Resolution: Screen resolution in pixels. This value determines the density category of the device. Having a screen size of 4.0 inches, type a value of 768 x 1280 and notice how the density value is 400 dpi. Change the screen size to 6.0 inches and the density value changes to hdpi. Now change the resolution to 480 x 800 and the density value is mdpi.
  • RAM: RAM memory size of the device.
  • Input: Indicate if the home, back, or menu buttons of the device are available via software or hardware.
  • Supported device states: Check the allowed states.
  • Cameras: Select if the device has a front camera or a back camera.
  • Sensors: Sensors available in the device: accelerometer, gyroscope, GPS, and proximity sensor.
  • Default Skin: Select additional hardware controls.

Create a new device with a screen size of 4.7 inches, a resolution of 800 x 1280, a RAM value of 500 MiB, software buttons, and both portrait and landscape states enabled. Name it as My Device. Click on the Finish button. The hardware definition has been added to the list of configurations.

Click on the Next button to continue the creation of a new virtual device. The next step is to select the virtual device system image and the target Android platform. Each platform has its architecture, so the system images that are installed on your system will be listed along with the rest of the images that can be downloaded (Show downloadable system images box checked). Download and select one of the images of the Lollipop release and click on the Next button.

Finally, the last step is to verify the configuration of the virtual device. Enter the name of the Android Virtual Device in the AVD Name field. Give the virtual device a meaningful name to recognize it easily, such as AVD_nexus5_api21. Click on the Show Advanced Settings button. The settings that we can configure for the virtual device are the following:

  • Emulation Options: The Store a snapshot for faster startup option saves the state of the emulator in order to load faster the next time. The Use Host GPU tries to accelerate the GPU hardware to run the emulator faster.
  • Custom skin definition: Select if additional hardware controls are displayed in the emulator.
  • Memory and Storage: Select the memory parameters of the virtual device. Let the default values, unless a warning message is shown; in this case, follow the instructions of the message. For example, select 1536M for the RAM memory and 64 for the VM Heap. The Internal Storage can also be configured. Select for example: 200 MiB. Select the size of the SD Card or select a file to behave as the SD card.
  • Device: Select one of the available device configurations. These configurations are the ones we tested in the layout editor preview. Select the Nexus 5 device to load its parameters in the dialog.
  • Target: Select the device Android platform. We have to create one virtual device with the minimum platform supported by our application and another virtual device with the target platform of our application. For this first virtual device, select the target platform, Android 4.4.2 – API Level 19.
  • CPU/ABI: Select the device architecture. The value of this field is set when we select the target platform. Each platform has its architecture, so if we do not have it installed, the following message will be shown; No system images installed for this target. To solve this, open the SDK Manager and search for one of the architectures of the target platform, ARM EABI v7a System Image or Intel x86 Atom System Image.
  • Keyboard: Select if a hardware keyboard is displayed in the emulator. Check it.
  • Skin: Select if additional hardware controls are displayed in the emulator. You can select the Skin with dynamic hardware controls option.
  • Front Camera: Select if the emulator has a front camera or a back camera. The camera can be emulated or can be real by the use of a webcam from the computer. Select None for both cameras.
  • Keyboard: Select if a hardware keyboard is displayed in the emulator. Check it.
  • Network: Select the speed of the simulated network and select the delay in processing data across the network.

The new virtual device is now listed in the AVD Manager. Select the recently created virtual device to enable the remaining actions:

  • Start: Run the virtual device.
  • Edit: Edit the virtual device configuration.
  • Duplicate: Creates a new device configuration displaying the last step of the creation process. You can change its configuration parameters and then verify the new device.
  • Wipe Data: Removes the user files from the virtual device.
  • Show on Disk: Opens the virtual device directory on your system.
  • View Details: Open a dialog detailing the virtual device characteristics.
  • Delete: Delete the virtual device.

Click on the Start button. The emulator will be opened as shown in the following screenshot. Wait until it is completely loaded, and then you will be able to try it.

In Android Studio, open the main layout with the graphical editor and click on the list of the devices. As the following screenshot shows, our custom device definition appears and we can select it to preview the layout:

Navigation Editor

The Navigation Editor is a tool to create and structure the layouts of the application using a graphical viewer. To open this tool navigate to the Tools | Android | Navigation Editor menu. The tool opens a file in XML format named main.nvg.xml. This file is stored in your project at /.navigation/app/raw/.

Since there is only one layout and one activity in our project, the navigation editor only shows this main layout. If you select the layout, detailed information about it is displayed on the right panel of the editor. If you double-click on the layout, the XML layout file will be opened in a new tab.

We can create a new activity by right-mouse clicking on the editor and selecting the New Activity option. We can also add transitions from the controls of a layout by shift clicking on a control and then dragging to the target activity.

Open the main layout and create a new button with the label Open Activity:

<Button
       android_id="@+id/button_open"
       android_layout_width="wrap_content"
       android_layout_height="wrap_content"
       android_layout_below="@+id/button_accept"
       android_layout_centerHorizontal="true"
       android_text="Open Activity" />

Open the Navigation Editor and add a second activity. Now the navigation editor displays both activities as the next screenshot shows.

Now we can add the navigation between them. Shift-drag from the new button of the main activity to the second activity. A blue line and a pink circle have been added to represent the new navigation. Select the navigation relationship to see its details on the right panel as shown in the following screenshot. The right panel shows the source the activity, the destination activity and the gesture that triggers the navigation.

Now open our main activity class and notice the new code that has been added to implement the recently created navigation. The onCreate method now contains the following code:

findViewById(R.id.button_open).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
MainActivity.this.startActivity(
new Intent(MainActivity.this, Activity2.class));
}
});

This code sets the onClick method of the new button, from where the second activity is launched.

Summary

This article thought us about the Navigation Editor tool. It also showed how to integrate the Google Play services with a project in Android Studio. In this article, we got acquainted to the AVD Manager tool.

Resources for Article:


Further resources on this subject:


LEAVE A REPLY

Please enter your comment!
Please enter your name here