Exploring the Android emulator
As we progress, it helps to be familiar with exactly how to use the Android emulator. If you haven't used the latest version of Android, some of the ways to achieve even simple tasks (such as viewing all the apps) can be different to how your current device works. In addition, we want to know how to use the extra controls that come with all emulators.
The emulator control panel
You probably noticed the mini control panel that appears beside the emulator when you run it. Let's go through some of the most useful controls. Take a look at this screenshot of the emulator control panel. I have annotated it to aid the discussion:
I will just mention the more obvious controls and go into a bit more depth when necessary:
- These are the window controls. They minimize or close the emulator window.
- From top to bottom, the first button is used to power-off the emulator, to simulate powering off the actual device. The next two icons raise and lower the volume.
- These two buttons allow you to rotate the emulator both left and right. This means that you can test what your app looks like in all orientations, as well as how it handles orientation changes while the app is running. The icons immediately underneath these take a screenshot and zoom in, respectively. Here is the emulator after being rotated horizontally:
- These icons simulate the back button, home button, and view running apps button. Have a play with these buttons – we will need to use them from time to time, including in Chapter 6, The Android Lifecycle.
- Press the button labelled 5 in the annotated image to launch the advanced settings menu, where you can interact with things such as sensors, GPS, the battery, and the fingerprint reader. Have a play around with some of these settings if you are curious:
Let's play around with the emulator itself.
Using the emulator as a real device
The emulator can emulate every feature of a real phone, so it is possible to write a whole book on it alone. If you want to write apps that your users love, then understanding a whole range of Android devices is well worth taking the time to do. I just want to point out a few of the most basic features here, because without these basic interactions, it will be hard to follow along with the book. Furthermore, if you have an old Android device, then some essential basics (such as accessing the app drawer) have changed and you might be left a little baffled.
Accessing the app drawer
Hold the mouse cursor on the bottom of the home screen and drag upward to access the app drawer (with all the apps); the following screenshot shows this action halfway through:
Now you can run any app installed on the emulator. Note that when you run one of your apps through Android Studio, it remains installed on the emulator and, therefore, is runnable from the app drawer. However, every change you make to the app in Android Studio will require you to run or install the app again by clicking on the play button on the Android Studio quick launch bar, as we have been doing.
Viewing active apps and switching between apps
To view active apps, you can use the emulator control panel, that is, the square labelled as number 4 on the screenshot of the emulator control panel. To access the same option using the phone screen (as you will have to do on a real device), swipe up, just as with accessing the app drawer, but do so only for about one quarter of the length of the screen, as shown in following screenshot:
You can now swipe left and right through the recent apps, swipe an app up to close it, or tap the back button to return to what you were doing before you viewed this option. Do try this out, as we will use these basic features quite often in this book.