Breaking News

3.Developing first android app

                                    Chapter 3

android turorial

☐The quickest way to get to know Android Studio is to use it to develop an app.

We'll start with a little mobile app that displays the message  “Hello World“.

☐The first step in the application development process is to create a new project within the Android Studio environment.

Begin, therefore, by launching Android Studio so that the “Welcome to Android Studio” screen appears.

🔳Creating the project

☐Once this window appears, Android Studio is ready for a new project to be created.

☐To create the new project, simply click on the Start a new Android Studio project option to display the first screen of the New Project wizard.

🔳Configuring the project

☐Enter MyFirstApplication as the application name and as the company domain name.

☐Set any location on your hard-drive to save your project . I have chosen D:\MyAndroidStudioProjects .

☐Click Next to select your target devices.

🔳Select target platform

☐On the form factors screen, enable the Phone and Tablet option and set the minimum SDK setting .

☐The higher the minimum SDK selection, the more the application will be restricted to newer Android devices.

☐A useful chart can be viewed by clicking on the Help me choose link.

🔳Selecting the app template

⬜Click Next, and you will be given the opportunity to choose a template for your app's main activity.

⬜For now we'll stick with Empty Activity.

⬜Select this template and click Next.

🔳Entering basic details

⬜In the customize the activity screen, keep the default values and click finish.

🔳Developing first app

⬜Android studio will respond that it is creating the project then take you to the project workspace.

⬜Now android studio displays our app with some default screens.

⬜The key thing to notice are that moving from left to right we have:

               🔵The project window.

               🔵The designer split into its palette and a layout window.
               🔵A component tree window and a properties window at the far right.

⬜However most of the time we will be using the project window and a layout window.


          The code Screen

🔲The default screen

⬜On the top of the screen we would see two tabs called activity_main.xml and

⬜The activity_main.xml file shows the initial user interface of our app.

⬜Click on this tab to open it's design view.

🔲The design screen

⬜The design tab allows us to drag and drop the components from palette to the main screen and then customize their properties.

⬜By default our screen contains a TextView ( in Android a TextView is same as Label of Java) with the sample text Hello World.

⬜Further in the next session we will see how to customize this screen.

🔲The Text Screen
⬜Another way to look at the activity_main.xml file is to open the text view.

⬜This view shows the complete XML code generated for designing the UI.

🔲Running the app
⬜There are two distinct ways of running an Android app using Android Studio:

                      🔵 We can use the emulator or

                      🔵A real Android device.

⬜The emulator only allows us to test a subset of thing and it is slow.

☐However for the moment running our first app on an emulator is quite enough to get started. 

☐All we have to do is click the green run icon in the top toolbar - or use the Run➝”Run app" menu item. 

☐When we do this for the first time it will take a while for the app to be compiled.

☐When our app is ready to be compiled we will see a dialog box appear which allows us to either select a running emulator or start one going.

⬜If there are no emulators listed then we will have to create one.

⬜Select the Create New Emulator button. This will present a dialog box where we can select the device we want to test on.

⬜The default is the Nexus 5 and for a first test we might as well use this.

⬜We can accept all of the defaults in this first run.

⬜If you need other devices we can use the AVD Manager to define them – which we will see later.

⬜Once we have at least one emulator defined we can select it and it will load and prepare to run our program.

⬜The whole process takes some time the first time we do it.

⬜And finally our app will be loaded to the emulator and the default text “Hello World” would be displayed.



No comments