1

When encapsulating a module on flutter in an existing application in java and using FlutterActivity, I had the problem of passing of string. If using variant:

Button mInvokeFlutterActivity = findViewById(R.id.invoke_flutter_activity);
mInvokeFlutterActivity.setOnClickListener(v -> startActivity(
        FlutterActivity.withNewEngine().initialRoute(link).build(context)
                .putExtra("background_mode", "opaque")
                .putExtra("destroy_engine_with_activity", true)
));

then in main.dart, can catch the link variable as window.defaultRouteName. But if use another intent:

 Button mInvokeFlutterActivity = findViewById(R.id.invoke_flutter_activity);
 mInvokeFlutterActivity.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
         startActivity(FlutterActivity.withCachedEngine("my_engine_id").build(context)           
        );
    }
});

then using window.defaultRouteName will become impossible. Can anyone tell me how to solve the problem?

2 Answers 2

1

"The concept of an initial route is available when configuring a FlutterActivity or a FlutterFragment with a new FlutterEngine. However, FlutterActivity and FlutterFragment don’t offer the concept of an initial route when using a cached engine. This is because a cached engine is expected to already be running Dart code, which means it’s too late to configure the initial route."

https://flutter.dev/docs/development/add-to-app/android/add-flutter-screen

Sign up to request clarification or add additional context in comments.

Comments

0

Use invoke method to get data from Java or Kotlin, read this article to understand how to use it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.