6 June 2014

Set up the adt? (Part - 2)

Continued from the Part - 1  ...

Step 1 : So you may are now able to see this page.
activity_main

Step 2 : Now click activity_main.xml circled in the image above . You will see the xml code of your application .
activity_main xml

The xml file is situated in MyFirstProject ->res -> layout folder (circled in above image)
The xml files contains two elements A <RelativeLayout> and a <TextView>
A layout defines how the elements are placed in a page (defines the orientation of elements).

TextView contains the text you want to display on the screen .
(Try to change the Hello world text to your name and look at the GraphicalLayout).

 Step 3 : Double click on src ->  com.example.MyFirstProject -> MainActivity.java
mainactivity java

The java file named MainActivity.java will be opened.
You will find the following elements in it .
  1. package name ( package com.example.MyFirstProject)
  2. List of imports(Click on + button besides the import).
  3. MainActivity class which extends Activity .
  4. An onCreate method with a Bundle type argument .
  5. A predefined class called  setContentView(R.layout.activity_main) which takes argument as xml file (activity_main.xml).
  6. Ignore the method onCreateOptionsMenu since it does not have effect on the execution of the app if you delete it .
Step 4 : Click on the AndroidManifest.xml file and then again click on AndroidManifest.xml to let the program launch .

Step 5 : 
Check the line android:name="com.example.myfirstproject.MainActivity" which has name of our class MainActivity, hence MainActivity class will be executed first .

Also check on the line which says <action android:name="android.intent.action.MAIN" /> .MAIN says that it is the page which is going to be launched at the first place .
action MAIN

Step 5 : Click on the green button above and run the project  as Android Application and press OK shown below .
run app

Step 6 : You will see a Android mobile popped up called the Emulator .
emulator start

Check the Console marked above to see the activities running on the emulator .

Step 7 : After some time the mobile screen will be seen. Just drag the lock screen and the application will be seen with Hello World returned on the screen. (Wait till the application loads on the screen) .

output 1emulator output

 And you have made an android application.....Congratulations.

Stay tuned with Made In Android

Previous Page Next Page Home
Top