I’m attempting to use Flutter’s url_launcher plugin to open webpages.
When I click a button url_launcher opens a webpage successfully. However, if I then navigate back by swiping left, or using the soft back button, the app crashes. The logs say
java.lang.RuntimeException: Unable to destroy activity
{uk.co.pottertour.map_edinburgh_guide_airbnb/io.flutter.plugins.urllauncher.WebViewActivity}:
java.lang.IllegalArgumentException: Receiver not registered:
io.flutter.plugins.urllauncher.WebViewActivity$1@8152196
It says WebViewActivity so presumably Url_Launcher isn’t opening an external browser but an in-app Webview.
This is pretty critical, this app is basically a hub for exciting things.
I was suspicious that my didChangeAppLifecycleState
function was causing the error since it occurred on resume, but no, it’s when Flutter runs build & rebuilds the screen.
I’ve tried commenting out parts of my build process that included url_launcher links, believing the rebuild triggered it, but this does not help. Perhaps there is some background asynchronous process, that throws this error before the app is painted to the screen. To do with url_launcher.
2
Answers
I had your same problem and I suggest you this solution if you don’t want an in-app handling with url_launcher (https://pub.dev/packages/url_launcher#browser-vs-in-app-handling):
Using
mode: LaunchMode.externalApplication
the link will open outside your app and you shouldn’t have any problems when you navigate back into your app.For now, you can override dependency with