Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splash screen dispose/remove after loaded

I am launching a splash screen in my xamarin android application and what happens is the splash screen keeps appearing on other pages as background.

Whatever I do it's there.

I have tried to "Finish" the activity,NoHistory=true but nothing ,keeps showing on other pages in the background.

Taken from https://alexdunn.org/2017/02/07/creating-a-splash-page-for-xamarin-forms-android/

Any ideas why?

      [Activity(Label = "MyApp",
    Theme = "@style/MyTheme.Splash",
    Icon = "@drawable/icon", 
    MainLauncher = true, 
    NoHistory = true,
    ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.tabs;
            ToolbarResource = Resource.Layout.toolbar;

            base.OnCreate(bundle);

            Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App(new AndroidInitializer()));      

        }
    }


     [Activity(
            Theme = "@style/MyTheme.Splash",
            MainLauncher = true,
            NoHistory = true,
            ScreenOrientation = ScreenOrientation.Portrait)]
        public class SplashActivity : AppCompatActivity
        {

            public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
            {
                base.OnCreate(savedInstanceState, persistentState);

            }


          protected override void OnResume()
         {
           base.OnResume();
             var startUp = new Task(() =>
            {
             var intent = new Intent(this, typeof(MainActivity));
            StartActivity(intent);
        });
    startUp.ContinueWith(t => Finish());

    startUp.Start();
    }

      <style name="MyTheme.Splash" parent ="Theme.AppCompat.Light">
        <item name="android:windowBackground">@drawable/splash_screen</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
      </style>
like image 342
developer9969 Avatar asked Nov 08 '17 13:11

developer9969


1 Answers

This is caused by Theme = "@style/MyTheme.Splash". Both activities use the same theme.

Create a different theme for the other activities.

<style name="MyTheme.Main" parent ="Theme.AppCompat.Light">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

Change the theme in Activity:

[Activity(
    Theme = "@style/MyTheme.Main",
    MainLauncher = true,
    NoHistory = true,
    ScreenOrientation = ScreenOrientation.Portrait)]
public class SplashActivity : AppCompatActivity
{

    public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
    {
        base.OnCreate(savedInstanceState, persistentState);

    }
}
like image 95
Mark Verkiel Avatar answered Oct 13 '22 09:10

Mark Verkiel