Running the Hello Android App
Understanding the basics of how to get an Android application up and running is a simple but detailed process. You’re now ready to see your hard work in action.
Running the app in the emulator
Starting your application is as simple as choosing Run→Run ‘app’. At this point, Android Studio will compile your app. When it’s done, choose Launch Emulator and select the emulator you just created. Check Use same device for future launches, and click OK. Android Studio compiles your application, deploys it to the emulator, and then runs it, as shown.
Look for “HAX is working and emulator runs in fast virt mode” in the Run app log at the bottom of Android Studio, as shown here:
If you don’t see this, then your emulator will likely run much slower than it could. To fix this, you will want to enable the
Intel HAXM virtual machine acceleration
Help! If your emulator never loads and stays stuck on the ANDROID screen(s), there’s no need to worry, comrade. The first time the emulator starts, it can take many minutes to finish loading because you’re running a virtual Linux system in the emulator. The emulator has to boot up and initialize. The slower your computer, the slower the emulator is in its boot process.
You can save valuable time by leaving the emulator running. The emulator doesn’t have to be loaded every time you want to run your application. After the emulator is running, you can change your source code and then rerun your application. Because you checked the Use same device for future launches option, Android Studio will reuse it when running your app.
When the emulator finishes loading, you see your app running with the words “Hello world!” as shown.
You’ve just created and started your first Android application.
Checking app logs
You can view the logs of your application in the Android tool window, as shown here. This tool window should have popped up automatically when you ran your app, but if it didn’t, you can access it by choosing View→Tool Windows→Android.
Inside the Android view, you’ll see your app’s log output in the logcat tab. Here’s an example log that you might see:
1885-1885/com.dummies.helloandroid I/art: Not late-enabling -Xcheck:jni (already on) 1885-1898/com.dummies.helloandroid I/art: Profiler disabled. To enable setprop dalvik.vm.profiler 1 1885-1885/com.dummies.helloandroid W/Resources: Preloaded drawable resource #0x1080093 (android:drawable/sym_def_app_icon) that varies with configuration!! 1885-1885/com.dummies.helloandroid I/am_on_resume_called: [0,com.dummies.helloandroid.MainActivity]
The logcat view provides valuable information on the state of your application. It lets you know it’s launching an activity, shows which device you’re connected to, and shows warnings and errors. In the previous example, you can see that the com.dummies.helloandroid.MainActivity, the activity you just wrote, was run and its on_resume was called: