Android developer expert pdf free download

Looking for:

30+ Free Flutter Books And Best Kotlin PDF

Click here to Download

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

In order to configure a device, enable the option in the Settings app on the device. To do this, open the Settings app, then select Applications Development. The result should look like Figure Using an Emulator for Development We all agree that it is necessary to test Android apps on a variety of different devices and hardware. As it is practically impossible to own every physical device, you will need to use an emulator to check configurations of hardware you don t have.

Some of the important reasons to use emulators include: Testing on different hardware configurations Validating on different versions of the Android OS Simulating load or other stress tests Viewing your UI on various screen sizes and resolutions 26 Chapter 3: Configuring Devices and Emulators. Enable USB debugging on a physical device Supported Features The emulator included in the standard toolkit is feature-rich, however there are some constraints.

Supported features Simulating telephony, including latency and connectivity Simulating text messaging Using an Emulator for Development It allows you to specify hardware and software options that will be used by the emulator to model an actual device. The easiest way is to use the graphical AVD manager. It is also possible to configure AVDs from the command line by passing configuration parameters to the android tool.

For the most part, you will likely want to use the graphical tool, as it is simple to use. You would use the command-line option when working with scripts or other noninteractive operations for instance, if you are creating emulator images on a build server, or using a batch operation to test your code on multiple device configurations. Start it by clicking on the icon or running the android tool from the command line.

The first time you launch it, you will see something similar to Figure The screen will display a list of existing emulator configurations. You will be able to create, edit, repair, start, or see details of the various AVDs you have configured. You will then use this simple form to set the various configuration options necessary. Android Virtual Devices They will be used to define the specific hardware parameters you wish to emulate. The options include: Name Identifies your current configuration image.

This can be anything you like, but you should choose a name that lets you identify the specific options offered by the AVD. I usually name these according to the device I am trying to emulate, e. Device Allows you to select a preconfigured image based on a variety of common devices. Target Specifies the version of the platform the device will run. The tool will allow you to specify only those platforms that you have downloaded to your environment. In other words, if you have not used the SDK Manager Chapter 1 to install the API you wish to use, you will not be able to create an emulator running that version.

See Using Hardware Acceleration on page 33 for information on how to enable it. Snapshot Enabling this feature gives you the ability to save and restore an emulator s state to a snapshot file. This can be useful for saving the state of an emulator, allowing you to quickly boot to a specific state, avoiding lengthy boot times. For more information, see Using the Emulator on page Skin Allows you to specify a particular screen size and resolution. It provides a set of standard screen configurations for a particular platform, or you can specify custom values.

Creating AVDs from the command line It can be useful to generate AVD images from the command line when you are scripting or using an environment where employing the GUI isn t practical. To create AVDs using this method, you need to pass command-line parameters to the android tool. To create an AVD, run the android create avd command and include parameters that specify the particular configurations.

Required parameters are a name for the AVD and the system image that should run on the emulator when it is invoked. If you want, you can also specify other options, such as SD card size, OS platform, skin, or a specific location in which to store user data files.

This directory contains the AVD configuration files, the user data image, the SD card image if configured , and any other relevant files. This file contains the location of the directory containing the AVD files. The default location of this directory is: Android Virtual Devices It is also possible to specify a different location for a specific AVD by including -p path as an option when you create the AVD.

If you do set a custom location for the. I will describe a few of the most common ones you will likely want to set for each emulator you create. If you want to learn about all the available options, this AVD Command Reference is an excellent source. The default value is 96, which is quite low. I suggest increasing this value substantially to improve emulator performance. I generally set it to , but you can set it higher if your hardware can support it. Keyboard support Defines whether the device will support the physical keyboard on your computer.

I always set this to yes, because it makes interacting with the device easier. You will be able to use your computer keyboard to interact directly with the Android OS, which makes typing much easier than trying to use the onscreen keyboard with your mouse.

Camera support Defines whether your emulator will support camera functionality. If your app requires a camera, make sure to set this value, as the default is no. You can specify if your emulator will support front, back, or both cameras. GPS support Will allow your device to support location functionality. The default for this is yes, so you will need to change it only if you specifically want to disable this functionality.

Cache partition size This value is used by the Google Play Store to determine whether a device can download an app from the market. It is worth testing with a variety of settings to make sure your app will work on 32 Chapter 3: Configuring Devices and Emulators. Advanced Emulator Configuration Working with the emulator can be frustrating. Some of the most common tasks like starting or deploying an app can take a long time. There are a few simple things you can do to make it faster, including using VM hardware acceleration, eliminating unnecessary functionality, and dedicating a CPU core to the emulator.

Using it can improve performance significantly, but there are also limitations to consider. Benefits Key benefits of HAXM include: Improved emulator performance, in particular, quicker startup and shorter deploy times. Better performance of graphics-intensive applications, particularly those that make use of OpenGL.

Better use of native hardware: if your development computer is robust, using HAXM will allow you to use it to its full potential. The performance characteristics of the emulator are not the same as you would find in the real world, because most current Android devices use different ARM-based processors.

Advanced Emulator Configuration Installing the HAXM software It is not enough to just download the tool; you also need to install it. You need to launch the installer process and accept the license agreement to complete the installation. In order to use this functionality on Linux, you also need to install the KVM software package. Instructions for this vary based on the particular version of the OS being used. You will see additional options for using the Intel-based system for your emulator.

Do not select the Snapshot option. Snapshots are not supported for emulators with graphics acceleration enabled. Validating that HAXM is running After you have installed all the correct components and started your correctly configured AVD, you can easily validate that everything is running correctly.

If it is, a notification indicating success is displayed in the console during startup Figure Generally this isn t something you need to see, and it s preferable not to waste precious seconds while it displays. You can disable the boot animation by adding the -no-boot-anim option to your AVD start command. For example: emulator -avd myavd.

This prevents it from contending for a CPU with other resource-intensive processes such as Eclipse. To do this, start the Windows Task Manager, select the Processes tab, right-click on the running emulator process, and click on Set Affinity option. Then you will be able to check or uncheck the CPU processor core s on which you want to run the application see Figure Finally, click OK to finish the setup. Dedicating a core to the emulator 38 Chapter 3: Configuring Devices and Emulators.

Now we ll discuss their use. An emulator is a very powerful tool that makes testing easier and allows the developer to simulate a variety of things that would be difficult to accomplish under realworld conditions. For instance, if you are writing a mapping application, you might need to test locations all over the world, and it would be impractical although quite a bit of fun to actually travel to each of these locations.

It eliminates the need to have physical devices to represent each configuration that you need to test. For instance, you will use emulators to mock various screen sizes and memory configurations. This chapter describes how to use the emulator to effectively test various parameters.

For the most part, emulators and physical devices interact with the ADT tools in the exact same way. In other words, the operations we discuss in this chapter perform the same way on an emulator as they will on a physical device. In most cases, a physical device is more limited, because options such as changing network configurations are locked down by the service provider. You will likely use many different combinations of physical devices and emulators to test thoroughly.

You can run as many different emulators and devices as you like. It is common for a developer to have many different emulator and physical devices running at the same time, then use each of them throughout the test cycle. It is worth noting that the emulator doesn t support certain actions, such as simulating accelerometer activity, or simulating some sensor activity such as the magnetometer.

This tool is also used to start the emulator instances as well. It provides options to control runtime parameters of the emulators you created.

To start it from within Eclipse, click the icon from the main toolbar. Or start it from the command line with the following command: android avd When you launch the AVD Manager, you will see a screen similar to Figure This screen displays a list of all the AVDs you have configured on your system, and some options for managing them.

To start an emulator, select a particular AVD and click the Start button. AVD Manager tool You are then presented with a secondary screen Figure that has a variety of options specific to running an emulator instance. Using them allows you to change the size, performance, and data of your emulator. Scale factor This allows you to adjust the size of the emulator on your computer screen. To specify a particular screen size, place a checkmark in the Scale Factor box.

Next, click the? Enter the resolution and size of your display. Then type a number in the Screen Size box. Your emulator will be started with the screen size you entered.

Snapshot This lets you save an emulator s state to a snapshot file and restore it later. This can be useful if you would like to preconfigure an emulator to start in a particular state every time, or would like to avoid the lengthy boot process when starting from scratch. This is a great way to speed up the time to boot an emulator, and will save a lot of time.

Emulator boot times can be reduced from many minutes to just seconds. Starting an emulator from the command line It s not absolutely necessary to use the AVD Manager to start an emulator. You can also start it from the command line.

This is useful when using scripts, or if you would like to run an emulator without the overhead of Eclipse. There are a variety of configuration options you can use when starting an emulator this way. There are options relating to networking, graphics acceleration, sensor abilities, and more. To see a complete list of options, type: emulator -help Using the Emulator For example, you could start an emulator with graphics acceleration turned on and boot animation disabled two good options you can use to improve performance.

This would look like: emulator -avd Nexus7 -gpu on -no-boot-anim Using snapshots to improve performance The snapshot is a view of your emulator including all data, the current UI being displayed, or any other sensor or data currently being used.

This snapshot can be very useful if you wish to start your emulator with a certain configuration or state multiple times.

In order to use snapshots with a particular AVD, it needs to be configured appropriately. Reread Creating AVDs on page 28 to review how to do this. You will notice three options in the snapshot section of the launch configuration tool. Wipe user data Refreshes your emulator image to remove all data and resets it to a clean configuration just as if it were started for the very first time. Launch from snapshot Allows you to restore your emulator to the state it was in when the last snapshot was taken.

If there is no snapshot in memory, this option is not enabled. Save to snapshot Triggers the system to save a snapshot of the current state of the emulator when you close it. I use snapshots as a way to save a clean emulator that I can recover quickly. I save a snapshot the first time I start the emulator, right after it has completed the boot sequence. From that point forward, I make sure I don t check the Save Snapshot box.

If I need a clean emulator image, I can just restart this emulator and thanks to snapshots, I will have a fully booted clean emulator ready to go. Saving and retrieving a snapshot Snapshots are such a great way of speeding up your emulator usage, it is worth going through an example to show exactly how they work. Let s step through setting up an emulator using snapshots so you can actually see it for yourself. If you haven t done this already, review Creating AVDs on page 28 to do it.

When you start your emulator, the options for snapshots will be enabled. The first time you start your emulator, you should select the Wipe user data and Save to snapshot options as shown in Figure This starts the emulator with a brand new image, and allows you to save your state when you close it down.

Once you have these checkmarks selected, you can press the Launch button to start the emulator. Depending on the speed of your hardware, this can take a long time anywhere from 90 seconds to many minutes.

After the wait, you have an emulator booted to its clean state Figure Enabling the options to save the initial snapshot Using the Emulator In this example, the state we ll save is the emulator started with the main Activity of an app displayed see Figure Now close the process; in this case, that means clicking the red circle on the top left to kill the window. This will take a little bit of time maybe up to a minute because a snapshot of the current state of the emulator is being saved, which will allow you to recover to this state easily.

AVD snapshot saved state Using the Emulator When you select this option, and press the Launch button, instead of the emulator starting from scratch which takes many minutes , it starts up to the state we saved when we shut down the emulator in the previous step. Because the emulator doesn t need to go through the entire boot process, startup time is drastically improved the emulator will start to a snapshot state in around 10 seconds. You will see your emulator booted right to the same place as shown in Figure Enabling the options to launch from snapshot 46 Chapter 4: Using Devices and Emulators.

The emulator consists of a screen and optionally a keyboard or navigation buttons, if they were enabled when you created your AVD Creating AVDs on page The emulator runs like a native application in your operating system, and can be closed or minimized just like any other window by clicking an X or red button at the top of the window. Using the Emulator Emulator anatomy The Devices Tool So how do you keep track of the emulators or devices you have hooked to your computer?

You can use the Devices tool shown in Figure , which allows you to see and control the various devices or emulators connected to your computer.

This will be the central location where you control your devices. You will start a variety of important operations from this window including memory inspection, location and network simulation, and UI inspection.

I ll also highlight frequently used, essential functionality you that you will access directly from this tab. The primary way to access the Devices tool is from a tab at the bottom of your screen see Figure The devices tab should be there by default. Viewing running devices using the Devices tool There is also a version of the tool that can be run from the command line without Eclipse. This is particularly useful for team members that might not have the full development suite installed, but could still benefit from using these tools.

This will show you all the devices both physical devices and emulators that are currently connected and available. You can use the arrow on the left to collapse or expand a particular device tree in order to see details about the current running processes. In Figure , you ll see different devices connected. The first two are emulators the icon and their name both signify this , and the last one in the list with the funny name that is a mix of letters and numbers is a physical device.

There are a variety of useful operations that can be launched from this tab, including: Debugging The first button on the top allows you to enter debugging mode. In this mode, you can attach the debugger to an application that is already running. This means that you can start an application, run it until it gets to the place you would like to test, and then start debugging from that point. This can be an efficient way to directly debug exactly the code you want and avoid other code paths.

See Chapter 10 for more information. Device screen capture The next button launches a utility that allows you to take a screenshot of what is currently displayed on your device. Pressing this will launch the dialog in Figure The dialog shows an image of whatever is currently displayed on the screen of your device, along with buttons across the top that will enable you to save, rotate, or refresh the image.

Reset ADB The upside-down triangle is a particularly important button. Pressing this allows you to access the controls to reset the ADB process. This resets connectivity between the computer and the devices.

You can use it if you encounter connectivity issues between your computer and device. Keyboard Shortcuts If you enabled keyboard support when you created your AVD see Emulator Options on page 32 , a variety of keys will be mapped between your computer keyboard and the emulator.

I have listed some of the more useful mappings in Table A description of each option can be found in the emulator documentation on the Android developer website.

Table It allows you to navigate the file system to discover which files are on the device, move files onto and off the device, and modify the file system by adding and rearranging folder locations. This allows you to do a variety of things, including: 50 Chapter 4: Using Devices and Emulators. It is installed by default on all system images included with the SDK, and is preinstalled on your emulator.

This application allows you to enable various settings on your device that will make it easier to test and debug. In addition to the standard debugging options, there are many other tools designed to help debug applications by enabling visuals when certain events occur such as touch events, or the UI thread being locked. These tools are very useful when you are testing on a real device, as you can quickly visualize many system operations.

You can find the icon labeled Developer Tools to launch the application in the main app drawer. It allows you to do a large variety of activities relating to testing, instrumenting, and inspecting the state of various systems on your device. A brief list of some of the core functions follows: If you are running a device with Android 4. You will need to know the secret way to enable them. To enable them, open the Settings app, scroll to the bottom, then click About phone or About tablet and then tap on the Build number at the bottom of the screen seven times.

After doing this, you will see a message that says Congratulations, you are now a developer, and the Developer options will be available. Accounts Tester Allows you to access and configure a variety of user accounts on the emulator. Very useful if you need to test logins or similar authorization functionality.

Bad Behavior Allows you to simulate a variety of issues, like creating ANR Activity Not Responding events, or crashing key systems like the main app thread or the system server. You can also see things like system locale, keyboard type, and display metrics such as density.

This can be extremely useful when trying to determine how your app looks on different resolution devices. Connectivity Allows you to modify the networking parameters or modify the WiFi connectivity of the device. This is useful when you need to test connectivity issues or how your app will perform without connectivity.

Development Settings Does a variety of things such as enable debugging, show system statistics such as running processes, CPU, and memory usage or display UI hints like showing the coordinates of touch points or flashing the screen during updates. Instrumentation Runs unit tests directly on the device. Media Scanner Scans the media folder of your SD card and identifies any media available for use.

Package Browser This tool should look familiar, as it is the same tool you use to manage apps from the Android Settings app installed on your device. It serves the same purpose managing applications here as well.

Pointer Location Displays visible lines and coordinates that allow the developer to closely determine specific touch points. Running Processes Presents a list of processes currently running. Sync Tester Tests third-party sync adapters. Terminal Emulation Opens a terminal, allowing command-line access to the Linux shell. Developer Tools Application If you would like to run this on an actual physical device, it is necessary to build a custom system image and sign the Dev Tools APK with the same key as the system image.

After signing the app correctly, you will be able to install it and run it on a device. This means that you can only run it on a rooted device, or on a device for which you built the system image. The system image signing key is generally only available to the hardware manufacturer. Designed as a plug-in to the Eclipse IDE, it leverages many Eclipse features including code completion, syntax highlighting, and JUnit integration.

There is also a rich ecosystem of plug-ins and additional features available to download and install from third-party developers. In addition to the standard IDE, there are a variety of Android-specific tools that have been integrated.

The close integration makes developing easier, so I recommend ADT as the fastest way to get started with Android development. Throughout this section and this book , I highlight many of the ways you can leverage the IDE to improve your experience writing Android code. Anatomy of the Eclipse Workspace You will be spending a lot of your development time within Eclipse, so you ll need to familiarize yourself with how it is organized. Figure shows the standard Eclipse layout.

Let s look at a few key areas: Standard Eclipse layout Package Explorer The window on the far left allows you to view all the code components included in your project. You can click on the small triangles to expand or minimize a particular tree, which will expand or minimize that section of the code appropriately.

Code Editor Seen in the middle of the screen, this is the area where you make changes to your code. The source code is color-coded to highlight different elements of syntax. For instance, variable definitions are displayed in blue, and method modifiers are displayed in purple. Outline The view on the far right displays the main sections of the code in a structured way. You can click on the triangles to expand and minimize certain sections, just as in the Package Explorer view.

If there is an error in your code, it will be listed here in red. You can click on any of the messages that appear here. This will open the code with the error and place the cursor at the location where the problem exists. Uncovering Additional Tools and Views The default layout for Eclipse likely won t have all the components you need to use. Several additional tools are available, as well as a few different ways to customize what is displayed Figure Adding views to Eclipse layout Anatomy of the Eclipse Workspace This displays a long list of tools under the Android section, as shown in Figure Leading health and fitness apps like MyFitnessPal, Oura, and Peloton just rolled out integrations with Health Connect to sync health data across their apps and deliver richer insights to their users.

Join many more developers using Health Connect today! Read more. This app is a life saver. We’d love to hear your app’s favorite response. We regularly upgrade and create new features that are useful for you. Great if you could share it with your loved ones. Hope you always feel satisfied when using the application. Have a nice day. Needs improvement. I would tolerate ads if the ads didn’t make the info on each pdf disappear! Thank you for your comment. Our team is always striving to improve and develop the functionality of the app.

You can try again with the new version. We believe we can satisfy you. You will then use this simple form to set the various configuration options necessary. Android Virtual Devices They will be used to define the specific hardware parameters you wish to emulate.

The options include: Name Identifies your current configuration image. This can be anything you like, but you should choose a name that lets you identify the specific options offered by the AVD. I usually name these according to the device I am trying to emulate, e. Device Allows you to select a preconfigured image based on a variety of common devices. Target Specifies the version of the platform the device will run. The tool will allow you to specify only those platforms that you have downloaded to your environment.

In other words, if you have not used the SDK Manager Chapter 1 to install the API you wish to use, you will not be able to create an emulator running that version.

See Using Hardware Acceleration on page 33 for information on how to enable it. Snapshot Enabling this feature gives you the ability to save and restore an emulator s state to a snapshot file. This can be useful for saving the state of an emulator, allowing you to quickly boot to a specific state, avoiding lengthy boot times.

For more information, see Using the Emulator on page Skin Allows you to specify a particular screen size and resolution. It provides a set of standard screen configurations for a particular platform, or you can specify custom values.

Creating AVDs from the command line It can be useful to generate AVD images from the command line when you are scripting or using an environment where employing the GUI isn t practical. To create AVDs using this method, you need to pass command-line parameters to the android tool. To create an AVD, run the android create avd command and include parameters that specify the particular configurations. Required parameters are a name for the AVD and the system image that should run on the emulator when it is invoked.

If you want, you can also specify other options, such as SD card size, OS platform, skin, or a specific location in which to store user data files. This directory contains the AVD configuration files, the user data image, the SD card image if configured , and any other relevant files. This file contains the location of the directory containing the AVD files.

The default location of this directory is: Android Virtual Devices It is also possible to specify a different location for a specific AVD by including -p path as an option when you create the AVD. If you do set a custom location for the. I will describe a few of the most common ones you will likely want to set for each emulator you create.

If you want to learn about all the available options, this AVD Command Reference is an excellent source. The default value is 96, which is quite low.

I suggest increasing this value substantially to improve emulator performance. I generally set it to , but you can set it higher if your hardware can support it. Keyboard support Defines whether the device will support the physical keyboard on your computer. I always set this to yes, because it makes interacting with the device easier.

You will be able to use your computer keyboard to interact directly with the Android OS, which makes typing much easier than trying to use the onscreen keyboard with your mouse. Camera support Defines whether your emulator will support camera functionality.

If your app requires a camera, make sure to set this value, as the default is no. You can specify if your emulator will support front, back, or both cameras. GPS support Will allow your device to support location functionality. The default for this is yes, so you will need to change it only if you specifically want to disable this functionality. Cache partition size This value is used by the Google Play Store to determine whether a device can download an app from the market.

It is worth testing with a variety of settings to make sure your app will work on 32 Chapter 3: Configuring Devices and Emulators. Advanced Emulator Configuration Working with the emulator can be frustrating. Some of the most common tasks like starting or deploying an app can take a long time. There are a few simple things you can do to make it faster, including using VM hardware acceleration, eliminating unnecessary functionality, and dedicating a CPU core to the emulator.

Using it can improve performance significantly, but there are also limitations to consider. Benefits Key benefits of HAXM include: Improved emulator performance, in particular, quicker startup and shorter deploy times.

Better performance of graphics-intensive applications, particularly those that make use of OpenGL. Better use of native hardware: if your development computer is robust, using HAXM will allow you to use it to its full potential. The performance characteristics of the emulator are not the same as you would find in the real world, because most current Android devices use different ARM-based processors.

Advanced Emulator Configuration Installing the HAXM software It is not enough to just download the tool; you also need to install it. You need to launch the installer process and accept the license agreement to complete the installation. In order to use this functionality on Linux, you also need to install the KVM software package. Instructions for this vary based on the particular version of the OS being used.

You will see additional options for using the Intel-based system for your emulator. Do not select the Snapshot option. Snapshots are not supported for emulators with graphics acceleration enabled.

Validating that HAXM is running After you have installed all the correct components and started your correctly configured AVD, you can easily validate that everything is running correctly. If it is, a notification indicating success is displayed in the console during startup Figure Generally this isn t something you need to see, and it s preferable not to waste precious seconds while it displays.

You can disable the boot animation by adding the -no-boot-anim option to your AVD start command. For example: emulator -avd myavd. This prevents it from contending for a CPU with other resource-intensive processes such as Eclipse. To do this, start the Windows Task Manager, select the Processes tab, right-click on the running emulator process, and click on Set Affinity option. Then you will be able to check or uncheck the CPU processor core s on which you want to run the application see Figure Finally, click OK to finish the setup.

Dedicating a core to the emulator 38 Chapter 3: Configuring Devices and Emulators. Now we ll discuss their use. An emulator is a very powerful tool that makes testing easier and allows the developer to simulate a variety of things that would be difficult to accomplish under realworld conditions. For instance, if you are writing a mapping application, you might need to test locations all over the world, and it would be impractical although quite a bit of fun to actually travel to each of these locations.

It eliminates the need to have physical devices to represent each configuration that you need to test. For instance, you will use emulators to mock various screen sizes and memory configurations. This chapter describes how to use the emulator to effectively test various parameters.

For the most part, emulators and physical devices interact with the ADT tools in the exact same way. In other words, the operations we discuss in this chapter perform the same way on an emulator as they will on a physical device. In most cases, a physical device is more limited, because options such as changing network configurations are locked down by the service provider.

You will likely use many different combinations of physical devices and emulators to test thoroughly. You can run as many different emulators and devices as you like. It is common for a developer to have many different emulator and physical devices running at the same time, then use each of them throughout the test cycle. It is worth noting that the emulator doesn t support certain actions, such as simulating accelerometer activity, or simulating some sensor activity such as the magnetometer.

This tool is also used to start the emulator instances as well. It provides options to control runtime parameters of the emulators you created. To start it from within Eclipse, click the icon from the main toolbar. Or start it from the command line with the following command: android avd When you launch the AVD Manager, you will see a screen similar to Figure This screen displays a list of all the AVDs you have configured on your system, and some options for managing them.

To start an emulator, select a particular AVD and click the Start button. AVD Manager tool You are then presented with a secondary screen Figure that has a variety of options specific to running an emulator instance.

Using them allows you to change the size, performance, and data of your emulator. Scale factor This allows you to adjust the size of the emulator on your computer screen. To specify a particular screen size, place a checkmark in the Scale Factor box. Next, click the? Enter the resolution and size of your display. Then type a number in the Screen Size box. Your emulator will be started with the screen size you entered. Snapshot This lets you save an emulator s state to a snapshot file and restore it later.

This can be useful if you would like to preconfigure an emulator to start in a particular state every time, or would like to avoid the lengthy boot process when starting from scratch. This is a great way to speed up the time to boot an emulator, and will save a lot of time.

Emulator boot times can be reduced from many minutes to just seconds. Starting an emulator from the command line It s not absolutely necessary to use the AVD Manager to start an emulator.

You can also start it from the command line. This is useful when using scripts, or if you would like to run an emulator without the overhead of Eclipse. There are a variety of configuration options you can use when starting an emulator this way. There are options relating to networking, graphics acceleration, sensor abilities, and more. To see a complete list of options, type: emulator -help Using the Emulator For example, you could start an emulator with graphics acceleration turned on and boot animation disabled two good options you can use to improve performance.

This would look like: emulator -avd Nexus7 -gpu on -no-boot-anim Using snapshots to improve performance The snapshot is a view of your emulator including all data, the current UI being displayed, or any other sensor or data currently being used. This snapshot can be very useful if you wish to start your emulator with a certain configuration or state multiple times. In order to use snapshots with a particular AVD, it needs to be configured appropriately. Reread Creating AVDs on page 28 to review how to do this.

You will notice three options in the snapshot section of the launch configuration tool. Wipe user data Refreshes your emulator image to remove all data and resets it to a clean configuration just as if it were started for the very first time. Launch from snapshot Allows you to restore your emulator to the state it was in when the last snapshot was taken. If there is no snapshot in memory, this option is not enabled. Save to snapshot Triggers the system to save a snapshot of the current state of the emulator when you close it.

I use snapshots as a way to save a clean emulator that I can recover quickly. I save a snapshot the first time I start the emulator, right after it has completed the boot sequence. From that point forward, I make sure I don t check the Save Snapshot box.

If I need a clean emulator image, I can just restart this emulator and thanks to snapshots, I will have a fully booted clean emulator ready to go.

Saving and retrieving a snapshot Snapshots are such a great way of speeding up your emulator usage, it is worth going through an example to show exactly how they work. Let s step through setting up an emulator using snapshots so you can actually see it for yourself. If you haven t done this already, review Creating AVDs on page 28 to do it. When you start your emulator, the options for snapshots will be enabled. The first time you start your emulator, you should select the Wipe user data and Save to snapshot options as shown in Figure This starts the emulator with a brand new image, and allows you to save your state when you close it down.

Once you have these checkmarks selected, you can press the Launch button to start the emulator. Depending on the speed of your hardware, this can take a long time anywhere from 90 seconds to many minutes. After the wait, you have an emulator booted to its clean state Figure Enabling the options to save the initial snapshot Using the Emulator In this example, the state we ll save is the emulator started with the main Activity of an app displayed see Figure Now close the process; in this case, that means clicking the red circle on the top left to kill the window.

This will take a little bit of time maybe up to a minute because a snapshot of the current state of the emulator is being saved, which will allow you to recover to this state easily. AVD snapshot saved state Using the Emulator When you select this option, and press the Launch button, instead of the emulator starting from scratch which takes many minutes , it starts up to the state we saved when we shut down the emulator in the previous step.

Because the emulator doesn t need to go through the entire boot process, startup time is drastically improved the emulator will start to a snapshot state in around 10 seconds.

You will see your emulator booted right to the same place as shown in Figure Enabling the options to launch from snapshot 46 Chapter 4: Using Devices and Emulators. The emulator consists of a screen and optionally a keyboard or navigation buttons, if they were enabled when you created your AVD Creating AVDs on page The emulator runs like a native application in your operating system, and can be closed or minimized just like any other window by clicking an X or red button at the top of the window.

Using the Emulator Emulator anatomy The Devices Tool So how do you keep track of the emulators or devices you have hooked to your computer?

You can use the Devices tool shown in Figure , which allows you to see and control the various devices or emulators connected to your computer. This will be the central location where you control your devices. You will start a variety of important operations from this window including memory inspection, location and network simulation, and UI inspection. I ll also highlight frequently used, essential functionality you that you will access directly from this tab.

The primary way to access the Devices tool is from a tab at the bottom of your screen see Figure The devices tab should be there by default.

Viewing running devices using the Devices tool There is also a version of the tool that can be run from the command line without Eclipse. This is particularly useful for team members that might not have the full development suite installed, but could still benefit from using these tools.

This will show you all the devices both physical devices and emulators that are currently connected and available. You can use the arrow on the left to collapse or expand a particular device tree in order to see details about the current running processes.

In Figure , you ll see different devices connected. The first two are emulators the icon and their name both signify this , and the last one in the list with the funny name that is a mix of letters and numbers is a physical device. There are a variety of useful operations that can be launched from this tab, including: Debugging The first button on the top allows you to enter debugging mode. In this mode, you can attach the debugger to an application that is already running.

This means that you can start an application, run it until it gets to the place you would like to test, and then start debugging from that point. This can be an efficient way to directly debug exactly the code you want and avoid other code paths.

See Chapter 10 for more information. Device screen capture The next button launches a utility that allows you to take a screenshot of what is currently displayed on your device. Pressing this will launch the dialog in Figure The dialog shows an image of whatever is currently displayed on the screen of your device, along with buttons across the top that will enable you to save, rotate, or refresh the image. Reset ADB The upside-down triangle is a particularly important button.

Pressing this allows you to access the controls to reset the ADB process. This resets connectivity between the computer and the devices. You can use it if you encounter connectivity issues between your computer and device. Keyboard Shortcuts If you enabled keyboard support when you created your AVD see Emulator Options on page 32 , a variety of keys will be mapped between your computer keyboard and the emulator.

I have listed some of the more useful mappings in Table A description of each option can be found in the emulator documentation on the Android developer website. Table It allows you to navigate the file system to discover which files are on the device, move files onto and off the device, and modify the file system by adding and rearranging folder locations.

This allows you to do a variety of things, including: 50 Chapter 4: Using Devices and Emulators. It is installed by default on all system images included with the SDK, and is preinstalled on your emulator.

This application allows you to enable various settings on your device that will make it easier to test and debug. In addition to the standard debugging options, there are many other tools designed to help debug applications by enabling visuals when certain events occur such as touch events, or the UI thread being locked.

These tools are very useful when you are testing on a real device, as you can quickly visualize many system operations. You can find the icon labeled Developer Tools to launch the application in the main app drawer. It allows you to do a large variety of activities relating to testing, instrumenting, and inspecting the state of various systems on your device. A brief list of some of the core functions follows: If you are running a device with Android 4.

You will need to know the secret way to enable them. To enable them, open the Settings app, scroll to the bottom, then click About phone or About tablet and then tap on the Build number at the bottom of the screen seven times. After doing this, you will see a message that says Congratulations, you are now a developer, and the Developer options will be available. Accounts Tester Allows you to access and configure a variety of user accounts on the emulator.

Very useful if you need to test logins or similar authorization functionality. Bad Behavior Allows you to simulate a variety of issues, like creating ANR Activity Not Responding events, or crashing key systems like the main app thread or the system server.

You can also see things like system locale, keyboard type, and display metrics such as density. This can be extremely useful when trying to determine how your app looks on different resolution devices. Connectivity Allows you to modify the networking parameters or modify the WiFi connectivity of the device. This is useful when you need to test connectivity issues or how your app will perform without connectivity. Development Settings Does a variety of things such as enable debugging, show system statistics such as running processes, CPU, and memory usage or display UI hints like showing the coordinates of touch points or flashing the screen during updates.

Instrumentation Runs unit tests directly on the device. Media Scanner Scans the media folder of your SD card and identifies any media available for use. Package Browser This tool should look familiar, as it is the same tool you use to manage apps from the Android Settings app installed on your device. It serves the same purpose managing applications here as well.

Pointer Location Displays visible lines and coordinates that allow the developer to closely determine specific touch points. Running Processes Presents a list of processes currently running. Sync Tester Tests third-party sync adapters. Terminal Emulation Opens a terminal, allowing command-line access to the Linux shell. Developer Tools Application If you would like to run this on an actual physical device, it is necessary to build a custom system image and sign the Dev Tools APK with the same key as the system image.

After signing the app correctly, you will be able to install it and run it on a device. This means that you can only run it on a rooted device, or on a device for which you built the system image. The system image signing key is generally only available to the hardware manufacturer.

Designed as a plug-in to the Eclipse IDE, it leverages many Eclipse features including code completion, syntax highlighting, and JUnit integration. There is also a rich ecosystem of plug-ins and additional features available to download and install from third-party developers. In addition to the standard IDE, there are a variety of Android-specific tools that have been integrated. The close integration makes developing easier, so I recommend ADT as the fastest way to get started with Android development.

Throughout this section and this book , I highlight many of the ways you can leverage the IDE to improve your experience writing Android code. Anatomy of the Eclipse Workspace You will be spending a lot of your development time within Eclipse, so you ll need to familiarize yourself with how it is organized.

Figure shows the standard Eclipse layout. Let s look at a few key areas: Standard Eclipse layout Package Explorer The window on the far left allows you to view all the code components included in your project.

You can click on the small triangles to expand or minimize a particular tree, which will expand or minimize that section of the code appropriately. Code Editor Seen in the middle of the screen, this is the area where you make changes to your code. The source code is color-coded to highlight different elements of syntax.

For instance, variable definitions are displayed in blue, and method modifiers are displayed in purple. Outline The view on the far right displays the main sections of the code in a structured way. You can click on the triangles to expand and minimize certain sections, just as in the Package Explorer view. If there is an error in your code, it will be listed here in red.

You can click on any of the messages that appear here. This will open the code with the error and place the cursor at the location where the problem exists. Uncovering Additional Tools and Views The default layout for Eclipse likely won t have all the components you need to use. Several additional tools are available, as well as a few different ways to customize what is displayed Figure Adding views to Eclipse layout Anatomy of the Eclipse Workspace This displays a long list of tools under the Android section, as shown in Figure To add one of these to your Eclipse layout, select it from the list.

Once it is placed in your screen, you can drag and drop the tab to move it wherever you would like. Viewing the options available in the Android menu The perspectives concept in Eclipse is a collection of tabs and tools organized in a predefined way.

We will cover each of these in detail later in the book. The steps to open a perspective shown in Figure are: 1. Select Window Open Perspective. Select the perspective you would like to display. Eclipse perspectives Quick Button There is a small button at the top of the menu bar that is easy to overlook. This button is a shortcut to run your project. It has the same functionality that is executed by invoking the Run as This button is the simplest way to run your app, as it is just a single button click as opposed to navigating a menu.

It is important to note that this works only if you are editing a Java file. If you are editing an XML file, nothing happens when you click the button not even an error dialog. Code Templates It can be difficult to understand the proper way to create Android classes. You need to know the proper naming standards, which methods are required, how to tie various resources together, and other patterns for creating proper classes. Code Templates This ensures that the basic format of the classes is correct and that they match the standard style for Android.

 
 

Expert Android Programming Free Pdf Book PDF Book | Free PDF Books

 
Free PDF Book Expert Android Programming Free Pdf Book, Computer Programming Books, Download Free Books in PDF Format. Download 50+ Best Flutter Books, Top Kotlin Books And Free App Development PDF. Expert Android Development Tutorials – Android, Activity, Intent, Adt. Pdf reader for android free download is one of the best choice pdf reader on Android phones with the free and available features.

 

Machine Learning | Google Developers

 
Lab 4 In class Hands-on Android Debugging Tutorial Submit lab 4 as PDF with your feedback and list each major step in this tutorial with screen shots. believe that writing about Android development was a powerful tool to help Feel free to write become a Kotlin for Android expert. Download 50+ Best Flutter Books, Top Kotlin Books And Free App Development PDF. Expert Android Development Tutorials – Android, Activity, Intent, Adt.

 
 

Leave a Comment