Project anatomy & hello world

30
1 •Android application development

Transcript of Project anatomy & hello world

Page 1: Project anatomy & hello world

• Android application development

Page 2: Project anatomy & hello world

Run Eclipse IDE

Page 3: Project anatomy & hello world

Run Eclipse IDE

Page 4: Project anatomy & hello world

• You can run android sdk manager to upgrade and install your android development tools!

Page 5: Project anatomy & hello world

• For the first time, everything should be already installed and upgraded to latest version!

• But, later you can use this tool to upgrade to recent versions.

Page 6: Project anatomy & hello world

• Now, create a android virtual device using android virtual device manager.• This device will be the emulator which will run your android applications!

Page 7: Project anatomy & hello world

• In the diagram, we see no virtual device, so we will need to create one.• In this stage, click New to create a new virtual device.

Page 8: Project anatomy & hello world

• Give a name to your virtual device, e.g., MyAVD• Select a Device that will be emulated. In this case, select a 4.0” WVGA

android device• Select other options as required and clock OK.

Page 9: Project anatomy & hello world

• Your android virtual device is now ready to run your android applications!• Now, its time to create the application itself!

Page 10: Project anatomy & hello world

• Create a New Android Application Project.• New->Android Application Project.

Page 11: Project anatomy & hello world

• Give application name, package name, and select other options. Click Next.

• Package name must be unique, so give it a unique name.• Select minimum required sdk as API8

Page 12: Project anatomy & hello world

• Deselect the customer launcher icon, in this stage we do not need it.• We can test it later.

Page 13: Project anatomy & hello world

• Select a blank activity, keep other things default.• After you finally click finish, your default android application will be ready

and opened automtically

Page 14: Project anatomy & hello world

• Your just created default application will look like this!• Android activity xml file is opened by default!

Page 15: Project anatomy & hello world

Before you run your app, you should be aware of a few directories and files in the Android project:

Page 16: Project anatomy & hello world

Folder, File & Description

• 1 srcThis contains the .java source files for your project. By default, it includes an MainActivity.javasource file having an activity class that runs when your app is launched using the app icon.

• 2 genThis contains the .R file, a compiler-generated file that references all the resources found in your project. You should not modify this file.

• 3 binThis folder contains the Android package files .apk built by the ADT during the build process and everything else needed to run an Android application.

Page 17: Project anatomy & hello world

Folder, File & Description(Cont.)

• 4 res/drawable-hdpiThis is a directory for drawable objects that are designed for high-density screens.

• 5 res/layoutThis is a directory for files that define your app's user interface.

• 6 res/valuesThis is a directory for other various XML files that contain a collection of resources, such as strings and colors definitions.

• 7 AndroidManifest.xmlThis is the manifest file which describes the fundamental characteristics of the app and defines each of its components.

Page 18: Project anatomy & hello world

• Now, you will run your default application. You need to open the file. Open the activity java file under src folder.

• Then click the run icon in the toolbar!

Page 19: Project anatomy & hello world

• For the first time run, you will be asked to select different options for running

• First, select Android Application in this stage. This means you are going to run the program as Android Application

Page 20: Project anatomy & hello world

• Be patient for the first to run avd! It may take 10-15 minutes to start up for the first time. After it is loaded, your application will be installed and main activity will be started!

• Congratulations on your first successful HelloWorld application!

Page 21: Project anatomy & hello world

• Now, test with emulators different button, icons, screens if you are not already familiar with android phone! Remember, the response might be a bit slow in your pc!

Page 22: Project anatomy & hello world

• Now, we will modify our HelloWorld android application!• Click on the activity xml file again! You will see the acitivity window!

Page 23: Project anatomy & hello world

• Remove the TextView item first from the window! Then drag and drop a new TextView and a Button into your window.

Page 24: Project anatomy & hello world

• To edit the properties of the button and textview you just added, go to activity xml view by clicking it. This will open the activity xml file rather than the graphical window!

Page 25: Project anatomy & hello world

• Now, first set, text propertyof button to something “Say Hi!” and remove the text property of the TextView by deleting the line.

• See the id of the textview, it will be used in the next task

Page 26: Project anatomy & hello world

• Open your main activity java file. Add a new function and import the class View. This function will be the handler of the button click in your android application.

Page 27: Project anatomy & hello world

• Now, add the following codes in your activity. This will set the text of the TextView to “Hello World” once the button is clicked!

Page 28: Project anatomy & hello world

• Now, open activity xml file and then add the following codes. This will connect the button to your added function. When user will press the button, the function will be called!

Page 29: Project anatomy & hello world

• Now, run your application again! Remember to keep the activity java file open.

• You will see your newly created application and the button! Click the button!

Page 30: Project anatomy & hello world

• Clicking the button, the textview will appear with text “Hello World”! Congratulation! You just completed an interaction between button, user and other component, i.e., TextView!