0

In a Xamarin.Android App, I need to display a splash screen image that comes from a http remote server.

So, I need to execute some code (WebClient...) before the MainLauncher Activity is displayed (My MainLauncher activity is basically a ImageView and a ProgressBar).

If I add my WebClient code in MainLauncher activity's OnCreate, then during the download a black screen is displayed. So I would like to execute my WebClient code BEFORE the mainlauncher is displayed.

Or any kind of trick would be OK!

Hope it is clear...

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
Teckel Cruel
  • 84
  • 1
  • 11

2 Answers2

1

You can create a class that extends Android.App.Application and add your code to its OnCreate method. It will be called before the MainLauncher activity on application startup. As pointed out here, this code is only invoked when the app is first loaded.

For example, add Application.cs (you can use Xamarin Studio's new file template for Android Activity) to the top level of your project with contents as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;    
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using MyApp.Core;

namespace MyApp.Droid
{
    public class Application : Android.App.Application
    {
        public Application(IntPtr javaReference, JniHandleOwnership transfer)
        : base(javaReference, transfer)
        {
        }

        public override void OnCreate()
        {
            base.OnCreate();

            // PUT SETUP CODE HERE
        }
    }
}
Community
  • 1
  • 1
coberlin
  • 508
  • 5
  • 7
0

You probably need one more activity. Immediately start the splash screen, and do your loading there; when your loading is done, redirect to your main activity.

TombMedia
  • 1,962
  • 2
  • 22
  • 27