# Our First Android Application Even though the HelloWorld program is trivial in introduces a wealth of new ideas -- the framework, activities, manifest, intents, UI, resources such as layouts, strings, etc. I know all just to print Hello World! There is a lot to take in regarding the Android program plumbing but an important separation principal presented in the single HelloWorld is the separation between UI design in XML and the program. Next, we consider a more complex with multiple UIs, activities and intents -- it's called MyFirstApp and the code is linked in so you can download and run it. What this lecture covers: * The MainActivity UI and code * Intents and starting another activity, namely, the DisplayMessageActivity * The DisplayMessageActivity UI and code * Application logging ## Checkout the demo project Download the demo the [MyFirstApp.zip](../code/myfirstapp.zip) app to go with these notes. I recommend that you code this project up from the notes rather than just open the project in Android Studio and run it -- but feel free to do that if you really want. As a rule I will include all source code examples and projects used in course when I can. ## Open an existing Android project in Android Studio To open each of the demo projects we give out, you will need to do this: - Click on the MyFirstApp.zip file and download and save the file on your desktop or download folder - Unzip the MyFirstApp.zip and you have MyFirstApp directory/ project - In Android Studio, click File->Open if you have already opened a project. Otherwise, click **Open an existing Android Studio project** at **Welcome to Android Studio** screen. Find the MyFirstApp directory and click **Choose**. The project should be opened and ready to run. ## Clean a project If for some reason there are errors try a clean. This is always a good thing to do if there are spurious errors in a project you know is clean. Go to **Build->Clean Project**. Hope that helped. ## MyFirstApp This application moves things forward. First it includes two activities. The main activity starts the second activity using an intent. When the user inputs a message on the UI of the first activity and clicks send the message is bundled up in an intent and the display activity started -- which displays the message on its own UI. Take a look at the screen dumps below: the first one is the UI rendered by the MainActivity UI, next the user enters a message and clicks the Send button -- and wham -- the DisplayMessageActivity is started to display the message in a larger -- sort of uncool -- font. There is a lot more to this simple program. Note, the menus for each UI is different. You can navigate back using the Up button instead of the back button from the DisplayMessageActivity UI. More on this later. ![](images/apprun_all.png) This program -- [myFirstApp](http://developer.android.com/training/basics/firstapp/building-ui.html) -- is taken from the Android developers with minor modifications. ## The MainActivity's UI Open the `app/java` folder and look at the `MainActivity.java` code. ## Create a linear layout The MainActivity's layout file is at `app/res/layout/activity_main.xml` ~~~ ~~~ ## Add a text field ~~~ ~~~ ## Add String Resources By default, your Android project includes a string resource file at app/res/values/strings.xml. Add a new string named "edit_message" and set the value to "Enter a message." (You can delete the "hello_world" string.) While you’re in this file, also add a "Send" string for the button you’ll soon add, called "button_send". ~~~ My First App Enter a message Send Settings MainActivity ~~~ ## Add a button ~~~