Skip to content

ensureInitializationCompleteAsync not calling callback if already initialized #39675

@chip2n

Description

@chip2n

When initializing Flutter asynchronously via FlutterMain.ensureInitializationCompleteAsync, the callback is never called if the engine is already initialized. This seems like unintended behavior, since the purpose of the function is to first ensure that initialization is completed, and after that's ensured run a piece of code.

Here's the line which returns without calling the callback:
https://github.com/flutter/engine/blob/2baba33c829703a1067072cd5c2c7fec1145a257/shell/platform/android/io/flutter/view/FlutterMain.java#L242-L244

In particular, I'd like to turn Flutter initialization into a coroutine:

suspendCoroutine<Unit> { continuation ->
    FlutterMain.startInitialization(applicationContext)
    val flutterShellArgs = FlutterShellArgs(arrayOf<String>())
    val handler = Handler()
    FlutterMain.ensureInitializationCompleteAsync(applicationContext, flutterShellArgs.toArray(), handler) {
        continuation.resume(Unit)
    }
}

But this coroutine won't resume if Flutter is already initialized (and I've found no way of checking if Flutter already is initialized as a workaround).

Am I approaching this wrong? Did I miss something?

Metadata

Metadata

Labels

a: existing-appsIntegration with existing apps via the add-to-app flowengineflutter/engine related. See also e: labels.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions