Repository: react-native
Issue: [android] Unable to add window -- token null is not valid; is your activity running? in Debug 
Labels: Issue: Author Provided Repro,Platform: Android,Needs: Triage :mag:

### Description

When starting a project in debug mode, android application crashes with an error
`FATAL EXCEPTION: main
                                                                                                    Process: com.myproject, PID: 18039
                                                                                                    android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
                                                                                                    	at android.view.ViewRootImpl.setView(ViewRootImpl.java:1312)
                                                                                                    	at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:405)
                                                                                                    	at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
                                                                                                    	at android.widget.PopupWindow.invokePopup(PopupWindow.java:1581)
                                                                                                    	at android.widget.PopupWindow.showAtLocation(PopupWindow.java:1347)
                                                                                                    	at android.widget.PopupWindow.showAtLocation(PopupWindow.java:1313)
                                                                                                    	at com.facebook.react.devsupport.DefaultDevLoadingViewImplementation.showInternal(DefaultDevLoadingViewImplementation.java:131)
                                                                                                    	at com.facebook.react.devsupport.DefaultDevLoadingViewImplementation.-$$Nest$mshowInternal(Unknown Source:0)
                                                                                                    	at com.facebook.react.devsupport.DefaultDevLoadingViewImplementation$1.run(DefaultDevLoadingViewImplementation.java:56)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:942)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                    	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)`

### React Native Version

0.72.6

### Output of `npx react-native info`

System:
  OS: macOS 14.0
  CPU: (8) arm64 Apple M1
  Memory: 82.39 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 16.17.0
    path: /usr/local/bin/node
  Yarn:
    version: 1.22.19
    path: /opt/homebrew/bin/yarn
  npm: Not Found
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.12.1
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.0
      - iOS 17.0
      - macOS 14.0
      - tvOS 17.0
      - watchOS 10.0
  Android SDK: Not Found
IDEs:
  Android Studio: Not Found
  Xcode:
    version: 15.0.1/15A507
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 18.0.2
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.6
    wanted: 0.72.6
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

### Steps to reproduce

1. Init project
2. Implement this code to MainActivity.kt
```
val CUSTOM_EXTRA_NAME = "RELAUNCHED"

override fun onCreate(savedInstanceState: Bundle?) {
        if (!intent.getBooleanExtra(CUSTOM_EXTRA_NAME, false)) {
            this.finish()
            intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
            intent.putExtra(CUSTOM_EXTRA_NAME, true);
            startActivity(intent);
        }
        super.onCreate(null)
    }

```
3. Got error

### Snack, screenshot, or link to a repository
[Link to repo](https://github.com/KirillCustom/react-native-crash)
<img width="1010" alt="image" src="https://github.com/facebook/react-native/assets/20151905/e41d61ef-213d-4c0b-8c53-07ee9453b886">