Reputation: 1048
I have a Flutter app which, like a browser, can be started from either the launcher or through a URI intent.
I have two files. The Dart file containing the main code and the Kotlin file containing the intent catching code.
My Kotlin code looks like:
class MainActivity : FlutterActivity() {
override fun onResume() {
super.onResume()
print("got at resume ${intent.data}")
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
print("At onCreate: ${intent.data}")
GeneratedPluginRegistrant.registerWith(this)
MethodChannel(flutterView, CHANNEL).setMethodCallHandler { call, result ->
print("got at onCall ${intent.data}")
}
}
So when I start it the first time, it outputs At onCreate: null"
. Makes sense, I started it without an intent.
Then I run adb shell am start -d "https://www.example.com"
. I expect it to (and when I wrote a demo Android app, it did) output print("At onCreate: https://www.example.com")
.
However, when I run it as a Dart app, I get FlutterActivityDelegate: onResume setting current activity to this
. Even when I send it to background and then run adb shell...
, I get got at resume null
.
The only way for me to get At onCreate: https://www.example.com
was to remove it from the previous app list. Then, and only then did I get the right output.
But even then, running adb shell am start -d "https://www.example.com/123"
produces the same bug as above.
How can I get the "new" intent in Dart/Kotlin?
Upvotes: 0
Views: 3252
Reputation: 39863
In your AndroidManifest.xml the android:launchMode
is relevant. If it's set to singleTop
, the Activity
will receive a call to onNewIntent(Intent)
:
Note that
getIntent()
still returns the original Intent. You can usesetIntent(Intent)
to update it to this new Intent.
Upvotes: 2