Repository: flutter
Issue: FlutterFragmentActivity  java.lang.IllegalArgumentException: No view found for id 0x1 (unknown) for fragment FlutterFragment
Labels: c: crash,platform-android,engine,P3,team-android,triaged-android

### Steps to reproduce

I am encapsulating Android native View into a Flutter plug-in and using it in Flutter. The process and ending are very smooth, but I need to use the LifecycleOwner and ViewModelStoreOwner functions, so I replace FlutterActivity with FlutterFragmentActivity, but execute setContentView(() in the onCreate function. R.layout.activity_main) crashes. Is there something wrong with the way I use it?

### Expected results

... ... 

### Actual results

```
java.lang.IllegalArgumentException: No view found for id 0x1 (unknown) for fragment FlutterFragment{a2acbe (468f7c25-2d23-4446-9411-9e24e8d4f347) id=0x1 flutter_fragment}
                 	at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:875)
                 	at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
                 	at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303)
                 	at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:439)
                 	at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2079)
                 	at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1869)
                 	at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824)
                 	at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727)
                 	at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManagerImpl.java:2663)
                 	at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManagerImpl.java:2613)
                 	at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:246)
                 	at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:542)
                 	at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1543)
                 	at android.app.Activity.performStart(Activity.java:8330)
                 	at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3670)
                 	at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
                 	at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
                 	at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
                 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
                 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
                 	at android.os.Handler.dispatchMessage(Handler.java:106)
                 	at android.os.Looper.loopOnce(Looper.java:201)
                 	at android.os.Looper.loop(Looper.java:288)
                 	at android.app.ActivityThread.main(ActivityThread.java:7872)
                 	at java.lang.reflect.Method.invoke(Native Method)
                 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
                 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
```

### Code sample

Android Code

MainActivity.kt
```
import android.os.Bundle
import io.flutter.embedding.android.FlutterFragmentActivity

class MainActivity : FlutterFragmentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main) // error code
    }

}
```

activity_main.xml
```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World" />

</LinearLayout>
```


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>Logs</summary>

```console
[Paste your logs here]
```

</details>


### Flutter Doctor output

```
[✓] Flutter (Channel stable, 3.13.2, on macOS 14.2.1 23C71 darwin-arm64, locale zh-Hans-CN)
    • Flutter version 3.13.2 on channel stable at /xx/xx/Documents/flutter_profile/flutter_sdk/flutter_3.13.2
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ff5b5b5fa6 (5 months ago), 2023-08-24 08:12:28 -0500
    • Engine revision b20183e040
    • Dart version 3.1.0
    • DevTools version 2.25.0
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /xx/xx/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /xx/xx/Library/Android/sdk
    • Java binary at: /Applications/Android Studio_2022.3.1.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A240d
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio_2022.3.1.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.6+0-17.0.6b829.9-10027231)

[✓] Android Studio (version 4.2)
    • Android Studio at /Applications/Android Studio_2021.4.2.2.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 11.0.8+10-b944.6916264)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.2)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 75.1.4
    • Dart plugin version 232.9559.10

[✓] VS Code (version 1.85.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.80.0

[✓] Connected device (3 available)
    • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64  • Android 13 (API 33) (emulator)
    • macOS (desktop)             • macos         • darwin-arm64   • macOS 14.2.1 23C71 darwin-arm64
    • Chrome (web)                • chrome        • web-javascript • Google Chrome 120.0.6099.234

```