Android is an open-source mobile operating system based on the Linux kernel. Developed by Google, it powers billions of devices worldwide — phones, tablets, wearables, TVs, and even cars.
Android's architecture consists of several layers:
An Activity goes through several states:
onCreate() — Called when the activity is first created.onStart() — The activity becomes visible to the user.onResume() — The activity starts interacting with the user.onPause() — Another activity is in the foreground.onStop() — The activity is no longer visible.onDestroy() — The activity is destroyed.// MainActivity.kt
package com.example.hello
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import android.widget.Button
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val greetingText: TextView = findViewById(R.id.greetingText)
val clickMeButton: Button = findViewById(R.id.clickMeButton)
clickMeButton.setOnClickListener {
greetingText.text = "Hello, Android!"
}
}
}
<!-- activity_main.xml -->
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/greetingText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome!"
app:layout_constraintCenter="parent" />
<Button
android:id="@+id/clickMeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"
app:layout_constraintBeneath="@id/greetingText" />
</androidx.constraintlayout.widget.ConstraintLayout>