Skip to content

[jni] Concurrency and Android activity lifecycle #2744

@HosseinYousefi

Description

@HosseinYousefi

Let's say that we continue exposing the android activity via some method such as Jni.androidActivity(int engineId). As long as we're running this on the main thread, in a synchronous method, it's fine to use it.

final a = Jni.androidActivity(PlatformDispatchers.instance.engineId);
Foo.method(a); // this is fine

However, if there is an async gap between the two, the code might be incorrect as the activity itself might have been changed:

final a = Jni.androidActivity(PlatformDispatchers.instance.engineId);
await someFuture; // async gap
Foo.method(a); // no longer ok, `a` might be incorrect.

This also means that the user should not be using the activity from other isolates.

We need to write these limitations in the documentation of androidActivity.

There are other things that this design doesn't resolve, namely the we would want to add various listeners to ActivityPluginBindings.

What is a general way to do something like image_picker?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions