The document provides step-by-step instructions for creating a basic "Hello World" Android application using Android Studio. It describes how to set up an Android virtual device, create a new Android project, add layout elements like buttons and text views, and write Java code to handle button clicks and update the text view. The application displays default text on launch and changes it to "Hello World" when the user clicks a button that was added to the layout.
4. • You can run android sdk manager to upgrade and install your android
development tools!
4
5. • 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.
5
6. • Now, create a android virtual device using android virtual device manager.
• This device will be the emulator which will run your android applications!
6
7. • 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.
7
8. • 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.
8
9. • Your android virtual device is now ready to run your android applications!
• Now, its time to create the application itself!
9
10. • Create a New Android Application Project.
• New->Android Application Project.
10
11. • 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
11
12. • Deselect the customer launcher icon, in this stage we do not need it.
• We can test it later.
12
13. • Select a blank activity, keep other things default.
• After you finally click finish, your default android application will be ready
and opened automtically
13
14. • Your just created default application will look like this!
• Android activity xml file is opened by default!
14
15. Before you run your app, you should be aware of a few
directories and files in the Android project:
15
16. Folder, File & Description
• 1 src
This 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 gen
This contains the .R file, a compiler-generated file that references all the
resources found in your project. You should not modify this file.
• 3 bin
This folder contains the Android package files .apk built by the ADT during
the build process and everything else needed to run an Android
application.
16
17. Folder, File & Description(Cont.)
• 4 res/drawable-hdpi
This is a directory for drawable objects that are designed for high-density
screens.
• 5 res/layout
This is a directory for files that define your app's user interface.
• 6 res/values
This is a directory for other various XML files that contain a collection of
resources, such as strings and colors definitions.
• 7 AndroidManifest.xml
This is the manifest file which describes the fundamental characteristics of
the app and defines each of its components.
17
18. • 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!
18
19. • 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
19
20. • 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!
20
21. • 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!
21
22. • Now, we will modify our HelloWorld android application!
• Click on the activity xml file again! You will see the acitivity window!
22
23. • Remove the TextView item first from the window! Then drag and drop a
new TextView and a Button into your window.
23
24. • 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!
24
25. • 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
25
26. • 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.
26
27. • Now, add the following codes in your activity. This will set the text of the
TextView to “Hello World” once the button is clicked!
27
28. • 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!
28
29. • 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!
29
30. • 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!
30