Skip to content

Document Why MethodChannel.Result#success is marked with @UiThread #95959

@cyanlink

Description

@cyanlink

Steps to Reproduce

  1. On Android, implement a custom MethodCallHandler.
  2. Run the result.success in a new Thread on purpose, as shown in sample code below.
  3. All works good on both Android and Dart. (unlike calling MethodChannel#invokeMethod on Android side where you will certainly get Exceptions)

I'm asking this question because I was trying to invokeMethod to Dart side in a MethodCallHandler callback, with TaskQueue enabled. This gave me the "not on main thread exception" (as they are in DartMessenger.DefaultTaskQueue), but the MethodChannel.Result#success did not.

Expected results: This function's annotation should be better documented to explain the necessity to run on UI thread.

Actual results: The function is marked @UiThread, but no such check is done in FlutterJNI by calling ensureRunningOnMainThread, and it all works normal, making the annotation a "false alarm".

Code sample
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
        when (call.method) {
            "getPics" -> Thread{result.success(true)}.run()
        }
    }
Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listframeworkflutter/packages/flutter repository. See also f: labels.packageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions