2
votes

A black screen with app title is showing when minimizing the app while loading splash screen , also the first screen will display after some time. Here is my splash activity and main activity classes.

[Activity(Theme = "@style/Theme.Splash", Icon = "@drawable/icon", MainLauncher = true, NoHistory = true,
    ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
    ScreenOrientation = ScreenOrientation.Behind)]
public class SplashActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        var dpWidth = Resources.DisplayMetrics.WidthPixels/Resources.DisplayMetrics.Density;


        RequestedOrientation = dpWidth > 700 ? ScreenOrientation.Unspecified : ScreenOrientation.Portrait;

        ThreadPool.QueueUserWorkItem(o => LoadActivity());
    }

    private void LoadActivity()
    {

        RunOnUiThread(() => StartActivity(typeof(MainActivity)));
    }


    public override void OnBackPressed()
    {
        Environment.Exit(0);
    }
} 



[Activity(Label = "HACCP", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : FormsApplicationActivity
{


    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        ActionBar.SetIcon(Android.Resource.Color.Transparent);

        Forms.Init(this, bundle);

        // some function //

        LoadApplication(new App());
    }

}
2
Issue is fixed when setting NoHistory flag to false.Aneesh.A.M

2 Answers

1
votes

You tagged Xamarin.Forms so it should be as simple as..

class App : Application
{
    public App()
    {
        MainPage = new MySplashPage();
    }
}

class MySplashPage : ContentPage
{
    public MySplashPage()
    {
        Task.Delay(3000); //show my pretty splash for 3 seconds
        Application.Current.MainPage = new MyOtherSpiffyPage();
    }
}
0
votes

Not certain if the activity attribute ScreenOrientation = ScreenOrientation.Behind) is causing any issues, we don't use that in our apps.

Here is a "standard" splash activity we do use, letting Xamarin.Android take care of timing etc:

public class SplashActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Start main.
        StartActivity(typeof(MainActivity));
    }
}

You might try simplifying your app in similar fashion.