Ad Code

Responsive Advertisement

Basic Android Program - 01

Question 01: Write a program to display Hello World.

Download hole Program / Project code, by clicking following link:

What is activity in android programming?
In Android programming, an Activity is a fundamental component of an Android application that represents a single screen with a user interface. It is an essential building block that defines the visual and interactive components of an application. An Activity is responsible for managing the user interface, handling user input, and coordinating with other components of the application.

Each Activity is implemented as a subclass of the Activity class in the Android SDK. The class provides methods for managing the lifecycle of the Activity, such as onCreate(), onPause(), and onDestroy(). These methods allow the Activity to perform specific tasks at different stages of its lifecycle, such as initializing resources, pausing and resuming tasks, and releasing resources. When an application is launched, Android creates a new Activity instance and displays it on the screen. The Activity then interacts with the user, responding to user input and providing feedback through the user interface. When the user interacts with the application, such as by clicking a button or entering text, the Activity handles the event and performs the necessary actions. An Android application can have multiple Activities, and each Activity can have its own user interface and behavior. Activities can also be started and stopped by other components of the application, such as services or broadcast receivers. For example, an Activity may be started to display a notification or respond to an incoming message. In summary, an Activity is a critical component of an Android application that provides the user interface and handles user input. It is responsible for managing the lifecycle of the application and interacting with other components of the application. Understanding the concept of Activity is essential for building successful Android applications.

Programming Code:

Following code write in: MainActivity.java
package com.go2collage.practical_01;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

Following code write in: activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="32sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Output:


Post a Comment

0 Comments

Ad Code

Responsive Advertisement