Repository: flutter
Issue: [Android] Hang on Splash Screen following process restoration when run with --start-paused
Labels: platform-android,tool,has reproducible steps,P2,a: state restoration,team-android,triaged-android,found in release: 3.16,found in release: 3.19

### Some Context

This was originally opened with the Dart-Code team [here](https://github.com/Dart-Code/Dart-Code/issues/4956) as I noticed the behavior only when running from VSCode. @DanTup was kind enough to look into it and prove that this is actually reproducible outside of VSCode using `--start-paused`. See @DanTup's comments on the linked ticket for more.

### Steps to reproduce

⚠️ **NOTE:** I created [this repo](https://github.com/btrautmann/restoration_bug) for reproducing (basically a simple `flutter create -e`, but allows all commands below to succeed automatically).

**Steps to reproduce the behavior (WITH VSCode):**
1. `flutter create -e restoration_bug`
2. `cd restoration_bug`
3. Open `main.dart` and make sure an Android device is selected. **We've found this reproduces 100% on Android 14 devices, but have not tested much outside that. Will test a variety of OS versions and report back via comments.**
4. On your device, [enable developer options](https://developer.android.com/studio/debug/dev-options) and set the **Background process limit** to **No background processes** (this will just help to have the system kill the process sooner than it normally would)
5. Run the app via the `Run` button on the `main` function
6. Background the app and run other apps until Android kills the Flutter process. You can be sure it is killed by running `adb shell pidof com.example.restoration_bug` and verifying there is NO output. If output exists, the app is still running under that process ID.
7. Once output of above command is clear, open the app back up via Recents or from Home Screen Launcher.
8. Note that the app never progresses beyond the Splash Screen which shows the Flutter logo.

**See @DanTup 's comment for [steps to reproduce WITHOUT VSCode](https://github.com/Dart-Code/Dart-Code/issues/4956#issuecomment-1908387548)** 

### Expected results

The app should land on the initial route which shows a `Hello world` message.

### Actual results

The app hangs on the splash screen. See video in section below.


### Code sample

See the repository linked in the **Steps to reproduce** section.

### Screenshots or Video

**This video shows how restoration behaves when run from VSCode and then when run after quitting the app:**

https://github.com/Dart-Code/Dart-Code/assets/8343465/843abf0d-bf48-4979-8f7a-7ee7ced4ecd6

### Logs

<details open><summary>Logs</summary>

```console
[Paste your logs here]
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.16.4, on macOS 14.3 23D56 darwin-arm64, locale en-US)
    • Flutter version 3.16.4 on channel stable at /Users/brandontrautmann/fvm/versions/3.16.4
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2e9cb0aa71 (6 weeks ago), 2023-12-11 14:35:13 -0700
    • Engine revision 54a7145303
    • Dart version 3.2.3
    • DevTools version 2.28.4

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/brandontrautmann/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_SDK_ROOT = /Users/brandontrautmann/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
    • 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 17.0.7+0-17.0.7b1000.6-10550314)

[✓] IntelliJ IDEA Community Edition (version 2023.2.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • 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

[✓] VS Code (version 1.85.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.80.0

[✓] Connected device (4 available)
    • moto x4 (mobile)          • ZY224LJPKC                • android-arm64  • Android 9 (API 28)
    • Brandon’s iPhone (mobile) • 00008110-000674483E20201E • ios            • iOS 17.3 21D50
    • macOS (desktop)           • macos                     • darwin-arm64   • macOS 14.3 23D56 darwin-arm64
    • Chrome (web)              • chrome                    • web-javascript • Google Chrome 120.0.6099.234

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>