I am currently integrating a google tap&pay SDK in my Flutter app. My app startActivityForResult
the native Google wallet Activity to add a card to wallet. Now wallet Activity wants to startActivityForResult
another activity in my app to get the verification code.
Now since all Flutter apps based on single activity architecture. If I start a new instance of the same Activity
in my flutter app the session gets invalidated for the previous instance. So I cannot work with multiple instances of the same Activity.
How can I add another Activity
in my Flutter app which will could be launched and share the same Flutter engine?
The diagram looks something like this:
A –> B –> C
- A: Flutter Activity
- B: Google Wallet Activity
- C: Another Activity for getting verification code
2
Answers
To add a second Android activity in your Flutter app, you can follow these steps:
MethodChannel
to communicate between Flutter and native Android. Here is an example of how you can do this:And in your SecondActivity.java:
Please note that you need to replace
com.example
with your own package name.FlutterEngineGroup
class. This allows you to share the same Flutter engine across multiple activities.I think you can use
flutter_isolate
packageFlutter isolate