Skip to content Skip to sidebar Skip to footer

How To Display Splash Screen On Onapplinkrequestreceived In Xamarin.forms- Android

I have implemented splash screen as below I have a splash activity as main launcher which starts MainActivity [Activity(Theme = '@style/MyTheme.Splash', MainLaunc

Solution 1:

Only problem here is that after clicking the link user sees a white screen instead of splash screen. I understand the problem because intentfilters are on mainactivity and splashactivity is never called. I moved intentfilters like below on splash activity, this time clicking on a link shows splash screen but OnAppLinkRequestReceived function is never called. Does anybody knows how can I achieve this?

Looking into the Xamarin.Forms Source Codes. You can find out that the calling chain of OnAppLinkRequestReceived is like this:

FormsAppCompatActivity.LoadApplication ->
FormsAppCompatActivity.CheckForAppLink(Intent) ->
Xamarin.Forms.Application.SendOnAppLinkRequestReceived(Uri) ->
Xamarin.Forms.Application.OnAppLinkRequestReceived(Uri).

And in CheckForAppLink(Intent), Xamarin.Forms do the following checks:

voidCheckForAppLink(Intent intent)
{
    string action = intent.Action;
    string strLink = intent.DataString;
    if (Intent.ActionView != action || string.IsNullOrWhiteSpace(strLink))
            return;

    var link = new Uri(strLink);
    _application?.SendOnAppLinkRequestReceived(link);
}

So, if you pass the Intent from your SplashActivity to MainActivity without Action and Data, SendOnAppLinkRequestReceived will never get called, thus OnAppLinkRequestReceived won't be called.

To fix the problem, you can add Action and Data manually to the intent in SplashActivity's OnCreate:

protectedoverridevoidOnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);

    string action = Intent.Action;
    string strLink = Intent.DataString;
    Intent intent = new Intent(Application.Context, typeof(MainActivity));
    if (Android.Content.Intent.ActionView == action && !string.IsNullOrWhiteSpace(strLink))
    {
        intent.SetAction(Intent.ActionView);
        intent.SetData(Intent.Data);
    }
    StartActivity(intent);
}

Post a Comment for "How To Display Splash Screen On Onapplinkrequestreceived In Xamarin.forms- Android"