Android is a mobile operating system (OS) developed by Google, widely used on various devices such as smartphones and tablets. It is an open-source system, allowing developers to freely create applications. This course will provide the basic information needed for developing Android apps using the Java language and will include practical coding examples.
History of Android
Android started in 2003 when Android Inc. was founded, and was acquired by Google in 2005. The first Android device was launched in 2008, and it has since been used on various devices, experiencing rapid growth. It currently occupies about 80% of the global smartphone market, with many developers distributing countless apps through the Android platform.
Android Architecture
The Android architecture is primarily composed of four main layers:
- Linux Kernel Layer: It provides stability and security and connects to the hardware abstraction layer (HAL) of Android and key services.
- Framework Layer: It provides APIs that app developers can access and includes key components such as Activity, Service, Content Provider, and Broadcast Receiver.
- App Layer: This consists of the applications provided to the actual user and includes the user interface (UI) and business logic.
- Manifest File: It defines the app’s metadata and specifies the app’s components, permissions, and hardware requirements.
Setting Up the Development Environment
To develop Android apps, you first need to set up your development environment. The required tools are as follows:
- Java Development Kit (JDK): This is the software needed to set up the Java environment. It can be downloaded from the Oracle website.
- Android Studio: This is the Android integrated development environment (IDE) provided by Google. Android Studio offers a range of tools, including a code editor, debugger, and emulator.
After setting up the environment, you can run Android Studio and create a new project.
How to Install Android Studio
- Download and install the JDK from the Oracle website.
- Download the installation file from the official Android Studio website.
- Run the downloaded file and follow the installation process.
Creating a New Project
Run Android Studio, and click “Start a new Android Studio project” to create a new project. The next step is to select a project template and enter the project name and package name. You can also set the minimum supported SDK version during this process.
Basic Concepts of Java-Based Android App Development
Android apps are composed of the following basic components:
- Activity: The basic element that composes the user interface (UI) and constructs the screen.
- Service: Handles tasks that run in the background. It runs without a UI.
- Broadcast Receiver: Receives and processes events occurring from the system or apps.
- Content Provider: Provides a standard interface for data sharing between apps.
Simple Android App Example
Now let’s create a simple ‘Hello World’ app. This app implements the functionality of displaying the text “Hello, World!” when the button is clicked.
MainActivity.java
package com.example.helloworld;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private TextView textView;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textView);
button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
textView.setText("Hello, World!");
}
});
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click the button"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"
android:layout_below="@id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />
</RelativeLayout>
Running the App
After writing the code, click the “Run” button in the Android Studio menu to execute the app on the emulator. The emulator provides a virtual environment for Android devices, allowing various device configurations to be emulated.
Conclusion
This course introduced the basics of Android app development using Java. We covered the history and architecture of the Android platform, how to set up the development environment, and implemented a simple example app. In future lessons, we will cover more diverse functionalities and explore content that can be applied in practice. Step into the world of Android app development!