Android Emulator
The Android emulator is an Android Virtual Device (AVD), which represents a specific Android device. We can use the Android emulator as a target device to execute and test our Android application on our PC.
The Android emulator provides almost all the functionality of a real device. We can get incoming phone calls and text messages. It also gives the location of the device and simulates different network speeds.
Android emulator simulates rotation and other hardware sensors. It accesses the Google Play store, and much more
Testing Android applications on emulators is sometimes faster and easier than doing on a real device. For example, we can transfer data faster to the emulator than to a real device connected through USB.
The Android emulator comes with predefined configurations for several Android phones, Wear OS, tablet, Android TV devices.
Requirement and recommendations
The Android emulator takes additional requirements beyond the basic system requirement for Android Studio. These requirements are given below:
- SDK Tools 26.1.1 or higher
- 64-bit processor
- Windows: CPU with UG (unrestricted guest) support
- HAXM 6.2.1 or later (recommended HAXM 7.2.0 or later)
Install the emulator
The Android emulator is installed while installing the Android Studio. However some components of the emulator may or may not be installed while installing Android Studio.
To install the emulator component, select the Android Emulator component in the SDK Tools tab of the SDK Manager.
Run an Android app on the Emulator
We can run an Android app from the Android Studio project, or we can run an app which is installed on the Android Emulator as we run any app on a device.
To start the Android Emulator and run an application in our project:
1. In Android Studio, we need to create an Android Virtual Device (AVD) that the emulator can use to install and run your app. To create a new AVD:-
1.1 Open the AVD Manager by clicking Tools > AVD Manager.
1.2 Click on Create Virtual Device, at the bottom of the AVD Manager dialog. Then the Select Hardware page appears.
1.3 Select a hardware profile and then click Next. If we don’t see the hardware profile we want, then we can create or import a hardware profile. The System Image page appears.
1.4 Select the system image for the particular API level and click Next. This leads to opening a Verify Configuration page.
1.5 Change AVD properties if needed, and then click Finish.
2. In the toolbar, choose the AVD, which we want to run our app from the target device from the drop-down menu.
3. Click Run.
Working with AndroidManifest.xml
The AndroidManifest.xml file contains information of your package, including components of the application such as activities, services, broadcast receivers, content providers etc.
It performs some other tasks also:
- It is responsible to protect the application to access any protected parts by providing the permissions.
- It also declares the android api that the application is going to use.
- It lists the instrumentation classes. The instrumentation classes provide profiling and other information. This information is removed just before the application is published etc.
This is the required xml file for all the android applications and located inside the root directory.
A simple AndroidManifest.xml file looks like this:
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”com.javatpoint.hello”
android:versionCode=”1″
android:versionName=”1.0″ >
<uses-sdk
android:minSdkVersion=”8″
android:targetSdkVersion=”15″ />
<application
android:icon=”@drawable/ic_launcher”
android:label=”@string/app_name”
android:theme=”@style/AppTheme” >
<activity
android:name=”.MainActivity”
android:label=”@string/title_activity_main” >
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application>
</manifest>
Elements of the AndroidManifest.xml file
The elements used in the above xml file are described below.
<manifest>
manifest is the root element of the AndroidManifest.xml file. It has a package attribute that describes the package name of the activity class.
<application>
application is the subelement of the manifest. It includes the namespace declaration. This element contains several sub elements that declares the application component such as activity etc.
The commonly used attributes of this element are icon, label, theme etc.
android:icon represents the icon for all the android application components.
android:label works as the default label for all the application components.
android:theme represents a common theme for all the android activities.
<activity>
activity is the subelement of application and represents an activity that must be defined in the AndroidManifest.xml file. It has many attributes such as label, name, theme, launchMode etc.
android:label represents a label i.e. displayed on the screen.
android:name represents a name for the activity class. It is a required attribute.
<intent-filter>
intent-filter is the sub-element of activity that describes the type of intent to which activity, service or broadcast receiver can respond to.
<action>
It adds an action for the intent-filter. The intent-filter must have at least one action element.
<category>
It adds a category name to an intent-filter.