Android Adventures - Getting Started With Android Studio 1.0
Android Adventures - Getting Started With Android Studio 1.0
Written by Mike James   
Tuesday, 03 February 2015
Article Index
Android Adventures - Getting Started With Android Studio 1.0
Project Structure
The Designer And The Code
Running the App

 

Get Started with the Emulator 

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. 

 

emulator1

 

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. 

 

emulatorrun

 

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.

Summary

  • 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. 


Android Adventures With Android Studio

cover

Contents

  1. Getting Started With Android Studio
  2. The Activity And The UI
  3. Building The UI and a Calculator App
  4. Basic Controls And Events
  5. Layout Containers
  6. UI Graphics A Deep Dive
  7. Menus & The Action Bar
  8. Menus, Context & Popup
  9. Resources
  10. Beginning Bitmap Graphics
  11. Lifecycle and State
  12. Spinners
  13. Pickers
  14. ListView And Adapters
  15. Using Android Studio (coming soon)

If you are interested in creating custom template also see:

Custom Projects In Android Studio

Androidgears

 

Where Next

In the next chapter we'll discover how to build a UI using components.

Meanwhile if you have any questions on what we've covered so far please let me know using the comments.

 

To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, FacebookGoogle+ or Linkedin,  or sign up for our weekly newsletter.

 

blog comments powered by Disqus 



Last Updated ( Sunday, 26 July 2015 )
 
 

   
Copyright © 2015 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.