Start a new topic

sendJsonObject and setJSONObjectReceivedCallback

Hello team wikitude,

I am having a problem with the sendJsonObject method.
Using the flutter plugin, version of sdk is 8.7.

All I am doing right now is calling the sendJsonObject like this when I am clicking something:


            action: "back"


That breaks the app immediately with the following error message:

Process: com.example.playground_wikitude, PID: 7851
java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: JsWorker
       at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(
       at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage(
       at io.flutter.embedding.engine.dart.DartMessenger.send(
       at io.flutter.embedding.engine.dart.DartExecutor.send(
       at io.flutter.view.FlutterNativeView.send(
       at io.flutter.plugin.common.MethodChannel.invokeMethod(
       at io.flutter.plugin.common.MethodChannel.invokeMethod(
       at com.wikitude.wikitude_plugin.ArchitectWidget.onJSONObjectReceived(
       at com.wikitude.architect.CallbackHandler.forwardJSONObject(SourceFile:317)
       at com.wikitude.architect.PlatformBridge.callAsyncImplInternal(Native Method)
       at com.wikitude.architect.PlatformBridge.callAsyncImpl(SourceFile:134)
       at com.wikitude.architect.PlatformBridge$a.a(SourceFile:66)
       at com.wikitude.architect.PlatformBridge$
Activity com.example.playground_wikitude.MainActivity has leaked IntentReceiver com.wikitude.architect.ArchitectView$NetworkStateReceiver@9284686 that
o unregisterReceiver()? Activity com.example.playground_wikitude.MainActivity has leaked IntentReceiver com.wikitude.architect.ArchitectView
red here. Are you missing a call to unregisterReceiver()?
       at android.content.ContextWrapper.registerReceiver(
       at com.wikitude.architect.ArchitectView.h(SourceFile:596)
       at com.wikitude.architect.ArchitectView.onPostCreate(SourceFile:579)
       at com.wikitude.wikitude_plugin.ArchitectWidget.onMethodCall(
       at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(
       at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(
       at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(
       at android.os.MessageQueue.nativePollOnce(Native Method)
       at android.os.Looper.loop(
       at java.lang.reflect.Method.invoke(Native Method)


What I want to achieve is, when the user clicks on let's say a point of interest, to send a JSON object to flutter, which then does some stuff with it...

Thanks in advance!

Great Matthew!

thank you very much!

Solved it. In

import android.os.Handler;

import android.os.Looper;


    public void onJSONObjectReceived(final JSONObject jsonObject) {


final Handler handler = new Handler(Looper.getMainLooper()); Runnable() {


public void run() {

channel.invokeMethod("jsonObjectReceived", jsonObject.toString());




2 people like this

I'm getting this issue too.

I've the same problem on Android, I set the callback in onArchitectWidgetCreated function 

Future<void> onArchitectWidgetCreated() async {
        .load("samples/01_ImageTracking_1_ImageOnTarget/index.html", () {
      print("ar works");
    }, (string) {
    this.architectWidget.setJSONObjectReceivedCallback((jsonObjectReceived) {


 The error is always 


java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: JsWorker
E/AndroidRuntime(15716): 	at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(


I think the problem is related to incorrect thread management in the flutter plugin Android implementation.

The problem is probably similar to the one in this post

Being able to communicate with the rest of the flutter application is essential for the development of a non-demo app.

I hope that those who developed it will find the solution

1 person likes this


I have found the implementation in Flutter that you provided, where the

 Future<void> onJSONObjectReceived(Map<String, dynamic> jsonObject) async


 is marked as async.

That once again results in the exception I posted initially.

Would you check this behaviour?


1 person likes this

... so it seems my actual problem lies in implementing the setJSONObjectReceivedCallback(). It causes the app to break, without it I am just told that I should

Use architectView.addArchitectJavaScriptInterfaceListener to receive the data.


... which is what I want to do with this:



Fast forward 10 minutes.

Apparently I put the setJSONObjectReceivedCallback() in a async method, causing it to break the app.

However, now I am setting it in the initState().

I am still told:

forwardJSONObject: There are no ArchitectJavaScriptInterfaceListener set.
Use architectView.addArchitectJavaScriptInterfaceListener to receive the data.


Can you give me an example of a correct implementation of that?

Thanks ind advance!

Oh, and I have tried the samples, they kinda work, I just couldn't find the missing piece.

Login or Signup to post a comment