我有一个Flutter应用程序,就像浏览器一样,可以从启动器或URI意图启动。
我有两个文件。包含主代码的Dart文件和包含意图捕获代码的Kotlin文件。
我的Kotlin代码如下:
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}")
}
}
因此,当我第一次启动它时,它会输出At onCreate: null"
。有道理,我没有意图就开始了。
然后我跑adb shell am start -d "https://www.example.com"
。我希望它(当我编写一个演示Android应用程序时,确实如此)输出print("At onCreate: https://www.example.com")
。
但是,当我将其作为Dart应用程序运行时,我得到FlutterActivityDelegate: onResume setting current activity to this
。即使我将其发送到后台然后运行adb shell...
,我也会获得got at resume null
。
我获得At onCreate: https://www.example.com
的唯一方法是将其从之前的应用列表中删除。然后,我才得到正确的输出。
但即便如此,运行adb shell am start -d "https://www.example.com/123"
会产生与上述相同的错误。
如何获得" new"意图在Dart / Kotlin?
答案 0 :(得分:2)
在 AndroidManifest.xml 中,singleTop
是相关的。如果设置为Activity
,则getIntent()
会收到onNewIntent(Intent)
的来电:
请注意
setIntent(Intent)
仍会返回原始意图。您可以使用{{1}}将其更新为此新Intent。