Application component consists of essential building blocks to develop an android application. These components should be added in the manifest file. Understand manifest.xml and resources here.[embedyt] https://www.youtube.com/watch?v=7UhGz4OD4AI[/embedyt]
Activity: It contains layout file and Java code to handle both user interaction and functionality on an application. If an application has more than one activity, then one of them should be marked as the activity that is presented when the application is launched.
Services: They handle background processing associated with an application.
For example, a service might play music in the background while the user is in a different application, or it might fetch data over the network without blocking user interaction with an activity.
Broadcast Receivers: Broadcast Receivers simply respond to broadcast messages from other applications or from the system. For example, applications can also initiate broadcasts to let other applications know that some data has been downloaded to the device and is available for them to use, so this is a broadcast receiver who will intercept this communication and will initiate appropriate action.
Content Providers: A content provider component supplies data from one application to others on request. The data may be stored in the file system, the database or somewhere else entirely.
Fragment: Represents a portion of the user interface in an Activity. Android Fragment is the part of the activity, it is also known as sub-activity. There can be more than one fragment in an activity. Fragments represent multiple screens inside one activity. Android fragment lifecycle is affected by activity lifecycle because fragments are included in an activity.
Some of the Application Components are Explained Here.
Now let’s create Your First Project. A Hello World! example:
Now create new Project in You Android Studio and open activity_main.xml in res-> layout folder.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="20dp" android:text="Hello World!" android:textSize="26dp" tools:ignore="MissingConstraints" /> </LinearLayout>
Now Run your Application click on Run Icon, connect your phone via USB to your PC or learn how to run an application from android studio to real devices.
In your MainActivity.java you will see onCreate() is @Override and has this line:
This binds your java file to your layout. R represent resources (everything in resource folder). then you have .layout to represent that this is a layout in the layout folder which is under resource folder.