Skip to content

仓库 files navigation

Android Java 动态 Lifecycle & Intent Navigation

Platform Language Components UI License

A foundational Android development starter in Java demonstrating core 动态 lifecycle management, Explicit Intent navigation, bundle payload transfer with putExtra, and user event handling.


📖 Overview

The Java-Classes project demonstrates the foundational building blocks of native Android development using Java. Designed as a clean reference for Android application architecture, it illustrates how Android activities operate, how inter-component communication is achieved via the Android Intent messaging framework, and how data is transferred across screens safely.

🎯 Key Learning Objectives

  • 动态 Lifecycle & Declarative Layout Binding: Understanding onCreate(Bundle savedInstanceState) and setContentView().
  • Explicit Intent Routing: Transitioning between distinct application activities using explicit class references (new Intent(Main动态.this, Second动态.class)).
  • Cross-动态 Data Passing: Packing primitive and string payloads into Intent Extras (intent.putExtra(key, value)) and extracting them in receiver activities (getIntent().getStringExtra(key)).
  • User Input Validation & Event Handling: Handling button click events with Java 8 lambdas (v -> { ... }), managing input state, and presenting Android Toast notifications.
  • Modern SDK Compatibility: Configured for Android 15 / SDK 36 using AndroidX AppCompat and ConstraintLayout.

🏗️ Architecture & Component Flow

sequenceDiagram
    autonumber
    actor User as App User
    participant Main as Main动态
    participant Intent as Explicit Intent (putExtra)
    participant Second as Second动态

    User->>Main: Enter name into EditText
    User->>Main: Click "Greet" Button
    Main->>Main: Validate input (!name.isEmpty())
    alt Input is Valid
        Main->>Intent: Instantiate Intent(Main动态.this, Second动态.class)
        Main->>Intent: putExtra("user_name", name)
        Main->>Second: start动态(intent)
        Second->>Second: onCreate() -> getIntent().getStringExtra("user_name")
        Second->>Second: Set TextView text to "Welcome [name]!"
        Second-->>User: Display personalized greeting screen
    else Input is Empty
        Main->>User: Display Toast error ("Please enter your name")
    end
Loading

✨ Core Concepts & Code Walkthrough

1. Explicit Intent Creation with Extras Payload

In Main动态.java, user input is verified and packaged into an explicit intent before launching the destination activity:

public class Main动态 extends AppCompat动态 {

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

        EditText editTextName = findViewById(R.id.etName);
        Button buttonGreet = findViewById(R.id.buttonGreet);
        TextView textViewGreets = findViewById(R.id.tvGreets);

        buttonGreet.setOnClickListener(v -> {
            String name = editTextName.getText().toString().trim();

            if (!name.isEmpty()) {
                textViewGreets.setText("Hello " + name + "!");

                Intent intent = new Intent(Main动态.this, Second动态.class);
                intent.putExtra("user_name", name);
                start动态(intent);
            } else {
                textViewGreets.setText("Please enter your name");
                Toast.makeText(this, "Please enter your name", Toast.LENGTH_SHORT).show();
            }
        });
    }
}

2. Intent Payload Extraction

In Second动态.java, the receiving activity extracts the data payload from the launching intent during its onCreate lifecycle hook:

public class Second动态 extends AppCompat动态 {

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

        TextView textViewRecieved = findViewById(R.id.tvRecieved);
        String nameReceived = getIntent().getStringExtra("user_name");

        textViewRecieved.setText("Welcome " + nameReceived + "!");
    }
}

📱 Project Structure

Java-Classes/
├── app/
│   ├── src/main/java/com/example/javaclasses/
│   │   ├── Main动态.java              # Primary launcher 动态 with input validation
│   │   └── Second动态.java            # Receiver 动态 displaying unpacked data
│   ├── src/main/res/
│   │   ├── layout/
│   │   │   ├── activity_main.xml          # Input form with ConstraintLayout
│   │   │   └── activity_second.xml        # Display layout with TextView
│   │   └── values/                        # Colors, styles, and strings
│   ├── src/main/AndroidManifest.xml       # 动态 declarations & intent filters
│   └── build.gradle.kts                   # Java 11 compilation, SDK 36 configuration
└── gradle/
    └── libs.versions.toml                 # Version catalog

🛠️ Technology Stack Matrix

Component Technology Version / Details
Platform Android API 24+ (Compile & Target SDK 36)
Language Java Java 11 (JavaVersion.VERSION_11)
Components Android Activities & Intents android.content.Intent, AppCompat动态
UI Layout Android ConstraintLayout androidx.constraintlayout:constraintlayout
Design Material Design Components com.google.android.material:material
Build System Gradle (Kotlin DSL) AGP 8.8+

🚀 Getting Started

Prerequisites

  • Android Studio Ladybug (2024.2.1+) or newer.
  • JDK 11 or JDK 17.
  • Android SDK 36.

Build & Run

  1. Clone the repository:
    git clone https://github.com/shayann07/Java-Classes.git
    cd Java-Classes
  2. Open in Android Studio: Open the folder and allow Gradle sync to complete.
  3. Assemble Debug Build:
    ./gradlew assembleDebug
  4. Run on Device: Launch via Android Studio or command line onto an active emulator or physical test device.

📄 License

This project is licensed under the MIT License — Copyright (c) 2026 shayann07.

关于

Core Android Java starter demonstrating 动态 lifecycles, explicit Intent navigation, Intent Extras data passing, and UI event handling.

Topics

Resources

Stars

0 stars

关注者

0 watching

复刻s

发布

贡献者

Languages