Splash screen on OnAppLinkRequestReceived in Xamarin.Android doesn't show

Yongqing Huang 241 Reputation points
2022-01-26T16:47:13.397+00:00

Hi,

My splash screen of Xamarin.Android works when I tap the app.

The app can also be started via OnAppLinkRequestReceived. But in this case, there is no splash screen. Only a white sceen is shown.

I have googled for this issue, changed my codes. But it is not fixed yet.

Could you give me an advice? Thank in advance.

My codes:

1.SplashActivity

namespace App1.Droid
{
[Activity(Theme = "@STYLE /MyTheme.Splash", MainLauncher = true, NoHistory = true)]
public class SplashActivity : Android.App.Activity
// I tried this line. It didn't help : public class SplashActivity : AndroidX.AppCompat.App.AppCompatActivity
{
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);  
    }  
}  

}

2.MainActivity

namespace App1.Droid
{
[Activity(Label = "AxinMobile", Icon = "@mipmap/icon", Theme = "@STYLE /MainTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]
[IntentFilter(new[] { Android.Content.Intent.ActionView },
Categories = new[] { Android.Content.Intent.CategoryDefault, Android.Content.Intent.CategoryLauncher, Android.Content.Intent.CategoryBrowsable },
AutoVerify = true,
DataSchemes = new[] { "http", "https" ,""}
)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

        Xamarin.Essentials.Platform.Init(this, savedInstanceState);  
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);  
        LoadApplication(new App());  
    }  
    public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)  
    {  
        Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);  

        base.OnRequestPermissionsResult(requestCode, permissions, grantResults);  
    }  
}  

}

  1. styles.xml
    <?xml version="1.0" encoding="utf-8" ?>
    <resources>
    <style name="MyTheme.Splash" parent ="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/splashscreen</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@Null </item>
    <item name="android:windowActionBar">true</item>
    </style>
    </resources>
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,357 questions
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,961 Reputation points
    2022-01-27T03:22:08.63+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    But in this case, there is no splash screen. Only a white sceen is shown.

    To display the splash screen when using deeplinking, please move the IntentFilter configuration from MainActivity to SplashActivity as below.

       [Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)]  
       [IntentFilter(new[] { Android.Content.Intent.ActionView },  
       Categories = new[] { Android.Content.Intent.CategoryDefault, Android.Content.Intent.CategoryLauncher, Android.Content.Intent.CategoryBrowsable },  
       AutoVerify = true,  
       DataSchemes = new[] { "http", "https", "" }  
       )]  
       public class SplashActivity : Android.App.Activity  
       {  
           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);  
           }  
       }  
    

    And to test this function, please close your application on the device first.
    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.