project anatomy & hello world

Post on 19-Jun-2015

210 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

• Android application development

Run Eclipse IDE

Run Eclipse IDE

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

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

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

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

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

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

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

• 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

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

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

and opened automtically

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

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

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.

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.

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

• 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

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

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

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

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

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

• 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

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

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

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

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

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

top related