1

Tengo el MainActivity configurado para hacer un splash (animación o logo antes de iniciar la aplicación), y me funciona, el problema es que antes de cargar el layout del splash "Main.axml" se queda como 3 segundos mostrando una pantalla negra con solo la etiqueta de la app ("Hola Mundo") y hasta luego el "Main.axml", entonces pierde el efecto deseado.

Alguna idea para revisar o mejorar.

Comparto código:

public class MainActivity : Activity
        
        protected override void OnCreate(Bundle bundle)
        {
            try
            {
                RequestWindowFeature(WindowFeatures.NoTitle); 
                base.OnCreate(bundle);                     
                SetContentView(Resource.Layout.Main);
            }
            catch (Exception Ex)
            {
                string LineErrorNumber=Ex.StackTrace.Substring(Ex.StackTrace.Length - 7, 7);
                ShowToast("Error en linea: " + LineErrorNumber + "\r\n" + "Error: " + Ex.Message, false);
            }
        }

protected override void OnResume()
        {
            try
            {                
                base.OnResume();
                Task startupWork = new Task(() => { SimulateStartup(); });
                startupWork.Start();
            }
            catch (Exception Ex)
            {
                string LineErrorNumber = Ex.StackTrace.Substring(Ex.StackTrace.Length - 7, 7);
                ShowToast("Error en linea: " + LineErrorNumber + "\r\n" + "Error: " + Ex.Message, false);
            }
        }
    
    async void SimulateStartup()
    {
        try
        {
            await Task.Delay(5000); //5 segundos mostrando el splash deseado.                
            
            var Intent = new Android.Content.Intent(this, typeof(LoginAux));
            StartActivity(Intent);
            
            Intent.Dispose();
        }
        catch (Exception Ex)
        {
            string LineErrorNumber = Ex.StackTrace.Substring(Ex.StackTrace.Length - 7, 7);
            ShowToast("Error en linea: " + LineErrorNumber + "\r\n" + "Error: " + Ex.Message, false);
        }
    }

1 respuesta 1

1

Para usar El splash se crea otro Activity, y tenes que pasarle 3 propiedades en el Decorador, " MainLancher= true" es para que sea este el principal Activity, "NoHistory = true" es para que no quede en la pila de navegacion este activity y por ultimo el Theme que lleva tu activity que contiene la imagen del splash.

Y el ultimo paso, en tu activity Principal que seria mainActivity, colocas MainLancher = false;

[Activity(Label = "Mi App", MainLauncher = true, NoHistory = true, Theme = "@style/ThemeSplash")]
    public class Splash : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            StartActivity( new Intent(Application.Context, typeof(MainActivity)));

            // Create your application here
        }
    }

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.