Share via

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

dg2k 1,416 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
            }

        }
    }
}


Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

Answer accepted by question author

Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,166 Reputation points Microsoft External Staff
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.

Was this answer helpful?


1 additional answer

Sort by: Most helpful
  1. Simon Wales 0 Reputation points
    2026-05-27T08:14:49+00:00

    Actually, you can do this.

    In your Platforms\Android\Resources\values folder create a styles.xml (if you do not already have one).

    Add the below stuff, as you need:

    <style name="Maui.SplashTheme" parent="Maui.MainTheme">
        <item name="android:windowSplashScreenBackground">@color/colorBrandedBackground</item>
    	<item name="android:windowSplashScreenAnimatedIcon">@drawable/thesplashscreenimage</item>
    	<item name="android:windowSplashScreenBehavior">icon_preferred</item>
    </style>
    

    Then create a drawable folder in Platforms\Android\Resources. Then create an xml file called thesplashscreenimage.xml (or whatever you like), just make sure the file name matches to @drawable/thesplashscreenimage value above.

    In this file at the actual icon image:

    <?xml version="1.0" encoding="utf-8" ?> 
    <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
        <foreground android:drawable="@drawable/your_icon_as_a_png" />
    </adaptive-icon>
    

    Then in the same folder place your icon png. In the example above it would be called 'your_icon_as_a_png.png'.

    Don't forget to add the actual colour for the background to the colors.xml in the values folder:

    	<color name="colorBrandedBackground">#ffffff</color>
    

    The key to making this work is the icon_preferred value in the android:windowSplashScreenBehavior property - https://developer.android.com/develop/ui/views/launch/splash-screen#java.

    (This also assumes your MainActivity Activity is using Theme = "@style/Maui.SplashTheme")

    Was this answer helpful?

    0 comments No comments

Your answer

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