First Android Application

 To create android application we need 2 files

 1) Xml file (activity_main.xml):- 

        Xml is extensible markup language which is used to carry the data. In android application xml file is used for front end or designing purpose. 

 2) Java / Kotlin file (MainActivity.java):-

       Java is an object oriented programming language . In android java is used for actual processing.


1)   Android Layout File (activity_main.xml)

  <?xml version="1.0" encoding="utf-8"?>  

----This is called xml prolog . where we specify version and utf pattern.

<LinearLayout        ---UI Group  

    xmlns:android="http://schemas.android.com/apk/res/android"       --- xsd location

    android:layout_width="match_parent"                                            --- Occupy entire width

    android:layout_height="match_parent"                                           --- Occupy entire height

   android: orientation="vertical"  >                                                     ---direction to place UI components

    <TextView                                                                                        ---UI Component

        android:layout_width="wrap_content"                                        --- Occupy entire width

        android:layout_height="wrap_content"                                       --- Occupy entire height

        android:text="Hello World" />

</LinearLayout>


Note:- 

   UI Group :- 

      UI group is used to arrange the UI components.

      UI groups are - 1)Linear Layout

                                2)Table Layout

                                3)Relative Layout

      UI components  :-

           UI components are used to create the graphical user interface for our application. like TextView, Button, EditText and RadioButton etc

2) Android Main Activity File (MainActivity.java)

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends Activity {        ---create a class as a child of Activity class

    @Override

    protected void onCreate(Bundle b) {

        super.onCreate(b);

        setContentView(R.layout.activity_main);

    }

}

Note:-

onCreate() --- like main() in c,c++ or java in android we are having onCreate() which invoke first.

Bundel --- which stores the state of application

setContentView () --- this method is used to connect xml file with java file.

Follow the following steps to run android application :-

To run android application there are two ways :

1) Android emulator

2)Testing on device (mobile)


1) Create an Android Virtual Device (AVD)

For running the android application in the Android Emulator, you need to create and AVD. For creating the AVD:

 Select the Window menu > AVD Manager

Click on the new button, to create the AVD

Now a dialog appears, write the AVD name e.g. myavd. Now choose the target android version e.g. android2.2.

click the create AVD


2) Testing on Device :

To test the application on your own device, follow the following steps on mobile device

 Go to settings - About Device - click seven times on Model Number - it will enable Developer option.

   you’ll need to enable USB debugging on the device.

Now go to Settings - Developer options - enable the USB Debugging .




Post a Comment

0 Comments