Question #261HardFlutter Basics

FLUTTER → FULL DETAILED ARCHITECTURE → flutter_app_how_running_in_android_device_detailed_architecture (Check the github - interview prep docs )

#flutter#android#architecture#git

Answer

Flutter App Architecture on Android

How a Flutter app runs on Android device:


Layer Architecture

text
┌─────────────────────────────────┐
│   Flutter Framework (Dart)      │  ← User code, widgets, state
├─────────────────────────────────┤
│   Flutter Engine (C++)          │  ← Rendering, input handling
├─────────────────────────────────┤
│   Android Runtime (ART)         │  ← Java/Kotlin JVM
├─────────────────────────────────┤
│   Android Framework             │  ← Activity, Services, Sensors
├─────────────────────────────────┤
│   Linux Kernel                  │  ← Process management, I/O
└─────────────────────────────────┘

Startup Process

  1. Android system launches MainActivity
  2. FlutterActivity created
  3. FlutterEngine initialized
  4. Dart VM starts
  5. main.dart executes
  6. FlutterView renders UI on screen

Main Components

FlutterEngine: Hosts Dart VM and rendering engine FlutterView: Native view displaying rendered output Platform Channel: Bridges Dart and native code

dart
// Platform channel example
static const methodChannel = MethodChannel('com.example.app/channel');

Future<void> callNativeCode() async {
  try {
    final result = await methodChannel.invokeMethod('getDeviceInfo');
    print(result);
  } catch (e) {
    print('Error: $e');
  }
}

App Lifecycle

text
AppLifecycleState.resumed
AppLifecycleState.inactive
AppLifecycleState.paused
AppLifecycleState.detached

Reference: Flutter Platform Architecture