There are two distinct ways of running an Android app using Android Studio.
You can use the emulator or a real Android device.
Eventually you will have to discover how to run an app on a real connected Android device because the emulator only allows you to test a subset of things and it is slow.
However for the moment running your first app on an emulator is quite enough to get started.
All you have to do is click the green run icon in the top toolbar - or use the Run,Run "app" menu item.
When you do this for the first time it will take a while for the app to be compiled. Subsequent runs are faster.
When your app is compiled and ready to do you will see a dialog box appear which allows you to either select a running emulator or start one going. When you first install Android Studio you get a default emulator - a Nexus 5 running KitKat - and you can simply select Launch emulator and click OK to get it running. If you need other devices you can use the AVD Manager to define them - a subject we will return to.
It usually takes quite a time for the AVD to start because it not only has to initialize the emulator it also has to boot Android just like a real device. There are also a few moments where nothing seems to be happening. Don't panic, something will happen eventually. You can monitor the loading of the emulation in the Run window which appears automatically at the bottom of Android Studio.
It does take a long time to start. However, you only have to do this once per debug session because the AVD can be reused and the app reloaded each time you make any changes, and this is quite a quick operation. Most Android programmers get into the habit of starting an AVD when they first start using Android Studio so that it is ready for testing whenever the program is.
Finally, remember to wait until the Android operating system is loaded and you see the familiar home screen before you start to wonder where your app is. Even when it is loaded it is a good idea to give it a few seconds for Android Studio to notice it and to upload your app. As the emulator is a complete Android device, you also need to unlock it. As long as you have been patient enough you should see your app.
In our case this isn't particularly impressive - just the words Hello Android World - but when you think of the journey traveled it really should impress.
From this point you can now modify the code or the layout and run the app again to see the effects of the changes. With luck you shouldn't have to load the emulator again. If anything goes wrong and you get in a mess then simply delete the project and create it from scratch again.
You still have a lot to discover about how to extend the app and make it useful but - the adventure has begun.
Android Studio makes creating Android apps a lot easier than other approaches and since the release of version 1.0 it is the only official way to do the job.
An app has at least one Activity and this defines a screen layout and a behavior. An Activity doesn't have to have a UI but in most cased it does have one.
To create a simple application use the Blank Activity template with no extras selected.
The screen layout is controlled by an XML markup file, Main_Activity.xml in our case stored in the res directory.
Android Studio provides a drag-and-drop designer that allows you to create a UI without having to work directly with theXML.
The behavior of the app is controlled by a Java file, MainActivity.java in our case stored in the java directory. You can edit the code in the Java file directly in Android Studio. The Java has to load and display the layout defined in the XML file.
To run an app you need either an emulator based AVD or a real Android device connected to the machine.
When you run the app you can select which AVD or which hardware device is used to test it. When you first start simply use the default AVD a Nexus 5.
You can modify and re-run your app without having to restart the AVD or any real hardware connected to the machine.