Open edgiardina opened 1 year ago
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
This is a deeper issue around the Shell. Push Notifications will also cause the TabBar to become unresponsive. At first, I thought this was only linked to Maui, but I painstakingly recreated my entire project in XF, which also appears to occur. Only upon using the FlyoutPage method did it solve the issue.
@logikonline Hmm. Strange. I launched deep linking in my XF version of my app and didn't see it.
The issue with the TabBar and the Shell, is only created with the Push Notification. The FlyoutPage or obsolete MasterDetail page will not do it. I suspect it is to do with the GotoAsync method since the PushAsync will still work but I bet the TabBar uses that GotoAsync since the route is used for those too.
@logikonline what's strange is that this exception happens before OnAppLinkRequestReceived fires in my App class. So the exception happens when the Intent brings the Shell App / tabbar to the front, and not when my app is asked to GoToAsync the target URL of the applinkrequest.
I understand, the issue I found is that the Shell is likely executing the same GotoAsync code behind the scenes prior to our interaction. I only call this out because that is what breaks when I try to interact with the app when I do have control.
Running repro sample I was not able to reproduce.
Command
adb \
shell am start \
-W \
-a android.intent.action.VIEW \
-d "https://www.deeplink.com/player.php?p=16927"
Output
Starting: Intent { act=android.intent.action.VIEW dat=https://www.deeplink.com/... }
Status: ok
LaunchState: UNKNOWN (0)
Activity: com.android.chrome/org.chromium.chrome.browser.document.ChromeLauncherActivity
WaitTime: 1074
Complete
Result
www.deeplink.com refused to connect
That your intent fired off the web browser is suspicious. did you receive a selection dialog on whether to open the fired intent in app or in browser?
edit: I just opened up the repro project and am not getting that specific error in android anymore. However, I am also not reaching the breakpoint I set on line 16 of App.xaml.cs when debugging and firing the intent, so I am pretty sure AppLinks / Deep Linking is still not functioning.
In the correct setup can confirm this is still a bug. Can reproduce.
Does anyone have a work around for this issue?
Using Tabs as main UI.
That your intent fired off the web browser is suspicious.
This would indicate that DeepLink URL was not intercepted by OS.
did you receive a selection dialog on whether to open the fired intent in app or in browser?
edit: I just opened up the repro project and am not getting that specific error in android anymore. However, I am also not reaching the breakpoint I set on line 16 of App.xaml.cs when debugging and firing the intent, so I am pretty sure AppLinks / Deep Linking is still not functioning.
OK. I will take a look again. Thanks for the feedback.
Verified this issue with Visual Studio Enterprise 17.7.0 Preview 3.0(.Net 8). But deploying to android emulator does not have the link to exist. https://github.com/edgiardina/MauiBug_DeepLinkCrash
the same issue...
Also for me. The same issue. Android 13, net7.0
I ask GitHub Copilot and it suggested 2 solutions as per below
Prompt: lauch a url via deep link cause this exception An unhandled exception of type 'System.InvalidOperationException' occurred in Mono.Android.Runtime.dll: 'This window is already associated with an active Activity (LntApp.MainActivity). Please override CreateWindow on LntApp.App to add support for multiple activities https://aka.ms/maui-docs-create-window or set the LaunchMode to SingleTop on LntApp.MainActivity.' at Android.Runtime.RuntimeNativeMethods.monodroid_debugger_unhandled_exception(Exception e) at Android.Runtime.JNINativeWrapper._unhandled_exception(Exception e) at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(_JniMarshal_PPL_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0) at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Activity activity, IApplication application, Bundle savedInstanceState) at Microsoft.Maui.MauiAppCompatActivity.OnCreate(Bundle savedInstanceState) at LntApp.MainActivity.OnCreate(Bundle savedInstanceState) in /Users/tiendinh/Projects/holistic/App/LntApp/Platforms/Android/MainActivity.cs:line 28. how to resolve
GitHub Copilot: To resolve the System.InvalidOperationException
related to launching a URL via a deep link, you need to either override the CreateWindow
method in your App class to support multiple activities or set the LaunchMode
to SingleTop
in your [MainActivity
].
Here are the steps to set the LaunchMode
to SingleTop
:
AndroidManifest.xml
file.<activity>
tag for your MainActivity
android:launchMode="singleTop"
attribute to the <activity>
tag.Here is an example of how your AndroidManifest.xml
should look:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.companyname.lntapp">
<application android:allowBackup="true" android:label="LntApp" android:theme="@style/MainTheme">
<activity android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Alternatively, if you need to support multiple activities, you can override the CreateWindow
method in your App class. Here is an example:
App.xaml.cs
file.CreateWindow
method.using Microsoft.Maui.Controls;
namespace LntApp
{
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new MainPage();
}
protected override Window CreateWindow(IActivationState activationState)
{
return new Window(new MainPage());
}
}
}
Choose the approach that best fits your application's requirements.
I went with option 1 and it is not crashing anymore but it still launch the web browser rather than the app so may be my configuration.
Description
Creating a MAUI app with Deep Linking intents, then firing those intents causes a java crash
Steps to Reproduce
.\adb shell am start -W -a android.intent.action.VIEW -d "https://www.deeplink.com/player.php?p=16927"
Link to public reproduction project repository
https://github.com/edgiardina/MauiBug_DeepLinkCrash
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 13 Pixel 5
Did you find any workaround?
No response
Relevant log output