How to display Splash screen on OnAppLinkRequestReceived in Xamarin.Forms-Android

I implemented a splash screen as shown below I have a burst of activity as the main launch that launches MainActivity

[Activity(Theme = "@style/MyTheme.Splash",  
              MainLauncher = true,  
              Immersive = true,
              ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait,
              NoHistory = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] 
    public class SplashActivity : AppCompatActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            var intent = new Intent(this, typeof(MainActivity));
            StartActivity(intent);         
        }

    }

and in my onstart mainactivity, I register all applications and intentional filters, as shown below.

 [Activity(Label = "myapp",
        Icon = "@drawable/icon",
        Theme = "@style/MyTheme",
         MainLauncher = false,
        ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]  
      [IntentFilter(new[] { Intent.ActionView },
      Categories = new[] {
            Intent.ActionView,
            Intent.CategoryDefault,
            Intent.CategoryBrowsable
      },
      DataScheme = "http",
      DataHost = "myapp.azurewebsites.net",
      DataPathPrefix = "/app/", AutoVerify = true)
  ]
    [IntentFilter(new[] { Intent.ActionView },
      Categories = new[] {
            Intent.ActionView,
            Intent.CategoryDefault,
            Intent.CategoryBrowsable
      },
      DataScheme = "https",
      DataHost = "myapp.azurewebsites.net",
      DataPathPrefix = "/app/", AutoVerify = true)
  ]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
     protected override void OnCreate(Bundle bundle)
        {

            // TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(bundle);


            global::Xamarin.Forms.Forms.Init(this, bundle);
            AndroidAppLinks.Init(this);       

            LoadApplication(new App());


    }

Still fine, everything works, when I click on the link, it redirects to my application and calls OnAppLinkRequestReceived in the App.Xaml.cs application of the forms.

   protected override async void OnAppLinkRequestReceived(Uri uri)
        {
                      // read link and redirect to a page
         }

, . , mainactivity splashactivity . , , ,   , OnAppLinkRequestReceived . - , ?

    [Activity(Theme = "@style/MyTheme.Splash", 
              MainLauncher = true,  
              Immersive = true,
              ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait,
              NoHistory = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]  
    [IntentFilter(new[] { Intent.ActionView },
      Categories = new[] {
            Intent.ActionView,
            Intent.CategoryDefault,
            Intent.CategoryBrowsable
      },
      DataScheme = "http",
      DataHost = "myapp.azurewebsites.net",
      DataPathPrefix = "/app/", AutoVerify = true)
  ]
    [IntentFilter(new[] { Intent.ActionView },
      Categories = new[] {
            Intent.ActionView,
            Intent.CategoryDefault,
            Intent.CategoryBrowsable
      },
      DataScheme = "https",
      DataHost = "myapp.azurewebsites.net",
      DataPathPrefix = "/app/", AutoVerify = true)
  ]
    public class SplashActivity : AppCompatActivity
0
1

, . , mainactivity splashactivity . , , , , OnAppLinkRequestReceived . - , ?

Xamarin.Forms. , OnAppLinkRequestReceived :

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

CheckForAppLink(Intent), Xamarin.Forms :

void CheckForAppLink(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);
}

, SplashActivity MainActivity Action Data, SendOnAppLinkRequestReceived , OnAppLinkRequestReceived .

, Action Data SplashActivity OnCreate:

protected override void OnCreate(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);
}
+1

All Articles