How to setup a Splash Screen when an Android Maui App is started by an external app?

dg2k 1,386 Reputation points
2023-11-16T18:24:10.2833333+00:00

I have a working app which I am now enhancing it by making it a Sharing Target. Consider that I am sending a simple text data such as a website link to my app. For this, I have added an Intent Filter as shown in the code below.

Everything works as expected except that when my app is launched by an external app (app acting as a Sharing Target) the Splash Screen is not shown and instead a blank page is shown. This makes sense because the Splash Screen is defined for the Main Activity and not for the Intent Filter.

My question is, therefore, how can I add a Splash Screen (or something equivalent like an animation) when my app is launched as Sharing Target?

I just want to improve on the dull blank page to a better UX,

[Activity(  Label = "@string/app_name",
            Exported = true, 
            Icon = "@mipmap/appicon",
            Theme = "@style/Maui.SplashTheme",
            MainLauncher = true,
            LaunchMode = LaunchMode.SingleTask,
            ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density, ScreenOrientation = ScreenOrientation.FullSensor)]

[IntentFilter([Intent.ActionSend], Categories = [Intent.CategoryDefault], Label = "@string/send_link",  DataMimeTypes = ["text/plain"])]


public partial class MainActivity : MauiAppCompatActivity
{
	protected override void OnCreate(Bundle savedInstanceState)
    {
		Intent intent = this.Intent;

        if (Intent.ActionSend.Equals(intent.Action) && intent.Type != null)
        {
            if ("text/plain".Equals(intent.Type))
            {
				string sharedText = intent.GetStringExtra(Intent.ExtraText);

				if(sharedText is not null) 
				{
					// use text data as required
				}
            }
        }
	}
}


// When app is a Sharing Target after it is launched

protected override async void OnNewIntent(Intent intent)
{
    base.OnNewIntent(intent);

    string action = intent.Action;
    string type = intent.Type;

    if (Intent.ActionSend.Equals(intent.Action) && intent.Type != null)
    {
        if ("text/plain".Equals(intent.Type))
        {
            string sharedText = intent.GetStringExtra(Intent.ExtraText);

            if (sharedText is not null)
            {
                // use text data as required
            }

        }
    }
}


.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,897 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 35,726 Reputation points Microsoft Vendor
    2023-11-17T05:34:27.7066667+00:00

    Hello,

    It is not possible to set a special splashscreen on Android when launching from an external app.

    how can I add a Splash Screen (or something equivalent like an animation) when my app is launched as Sharing Target?

    For transition animations for adding Activities to Android applications, you can refer to Start an activity using transitions.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, 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