Description
Summary
After repeatedly rebooting an Android device with a Flutter app that was launched using flutter run and has an active foreground service, the app occasionally freezes on the splash screen. In this state, the Dart main() function is not executed, and no Dart isolate is started. This issue does not occur when the app is installed via flutter build apk.
Steps to reproduce
- Make sure the app starts a foreground service (e.g., Bluetooth, sensor tracking), and then close the UI while keeping the service alive.
- While the foreground service is still running in the background, run flutter run to start the app again (debug build via tooling).
- Reboot the device repeatedly (up to ~10 times). The issue appears after a random number of reboots.
- After one of the reboots, observe:
- The splash screen appears but does not transition.
- The foreground service is still running.
- The Flutter main() function is not executed.
- This issue does not occur when:
- Running the app from a release APK
- Using Android Studio's native build system
Expected results
After rebooting the device, the Flutter app should fully start.
The main() function should be executed, and the splash screen should transition to the main UI as expected.
Actual results
After several device reboots (when the app was originally launched using flutter run with a foreground service running), the Flutter app gets stuck on the splash screen and never proceeds to the main UI.
Key observations:
- The Dart main() function is never executed.
- The foreground service remains active and continues running in the background.
- Tapping the app icon again does not fix the issue unless the app is force-stopped.
- The issue does not occur if the app was built and installed via flutter build apk.
Code sample
Code sample
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
print('Flutter main() started'); // Used to detect if isolate starts
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
static const MethodChannel channel =
MethodChannel('com.example/foreground_service');
String _status = 'Waiting for foreground service...';
@override
void initState() {
super.initState();
startForegroundService();
}
Future<void> startForegroundService() async {
try {
await channel.invokeMethod('startForegroundService');
setState(() {
_status = 'Foreground service started.';
});
} on PlatformException catch (e) {
setState(() {
_status = 'Failed to start service: ${e.message}';
});
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Reboot Splash Issue Demo',
home: Scaffold(
appBar: AppBar(title: const Text('Splash Issue Demo')),
body: Center(child: Text(_status)),
),
);
}
}
Screenshots or Video
Screenshots / Video demonstration
Logs
Logs
[Paste your logs here]
Flutter Doctor output
Doctor output
[Paste your output here]
[!] Flutter (Channel stable, 3.32.0, on macOS 14.6 23G80 darwin-arm64, locale ko-KR) [2.1s]
• Flutter version 3.32.0 on channel stable at /Users/kwakjoohyeong/development/flutter
! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/3.5.3/libexec/bin/dart, which is not inside your current Flutter SDK checkout at
/Users/kwakjoohyeong/development/flutter. Consider adding /Users/kwakjoohyeong/development/flutter/bin to the front of your path.
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision be698c48a6 (5주 전), 2025-05-19 12:59:14 -0700
• Engine revision 1881800949
• Dart version 3.8.0
• DevTools version 2.45.1
• If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [3.2s]
• Android SDK at /Users/kwakjoohyeong/Library/Android/sdk
• Platform android-35, build-tools 35.0.0
• Java binary at: /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home/bin/java
This JDK is specified in your Flutter configuration.
To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
• Java version Java(TM) SE Runtime Environment (build 17.0.12+8-LTS-286)
• All Android licenses accepted.
[!] Xcode - develop for iOS and macOS (Xcode 16.0) [2.8s]
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 16A242d
! CocoaPods 1.15.2 out of date (1.16.2 is recommended).
CocoaPods is a package manager for iOS or macOS platform code.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/to/platform-plugins
To update CocoaPods, see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods
[✓] Chrome - develop for the web [9ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2024.3) [9ms]
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)
[✓] VS Code (version 1.95.1) [8ms]
• VS Code at /Users/kwakjoohyeong/Downloads/Visual Studio Code.app/Contents
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] VS Code (version 1.96.0) [8ms]
• VS Code at /Users/kwakjoohyeong/Downloads/Visual Studio Code 2.app/Contents
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
</details>