title: Xamarin.Android using async method on background thread causes screen flash
body: <p>So I'm trying to create a loading/splash screen for an app that I'm creating. Basically, if the user isn't authenticated, then they shouldn't be able to access the other parts of the app. Additionally, I'd like the app to attempt to sync the necessary database objects before it loads up the main activity.</p>
  
  <p>The problem is that when I call the Authenticate() method and the InitLocalStoreAsync() methods, the screen flashes (almost like an activity reload, or like the app is doing something that I don't understand that's hiding the activity) while the methods are executing. I'd like that not to happen.</p>
  
  <p>I'm very new to Android App Dev and even newer to Xamarin.</p>
  
  <p>I'm using modified code that comes from the Azure Mobile Services tutorial on authentication etc.</p>
  
  <p>Should I be somehow executing these methods using RunOnUiThread? If so, how do I await in conjunction with RunOnUiThread? Or should I be doing this in a completely different way?</p>
  
  <p>I'm very lost. I've tried to search and find tutorials to follow, but I can't seem to find the answer. Here's the code so far:</p>
  
  <pre><code>protected override async void OnCreate (Bundle bundle)
      {
          base.OnCreate (bundle);
          SetContentView (Resource.Layout.Activity_Splash);
          // Create your application here
  
          try{
              CurrentPlatform.Init ();
  
              // Create the Mobile Service Client instance, using the provided
              // Mobile Service URL and key
              client = new MobileServiceClient (applicationURL, applicationKey);
              statusText = FindViewById&lt;TextView&gt; (Resource.Id.SplashStatusText);
  
              ThreadPool.QueueUserWorkItem(x =&gt; Initialize());
  
          }catch(Java.Net.MalformedURLException){
              CreateAndShowDialog (new Exception ("There was an error creating the Mobile Service. Verify the URL"), "Error");
          }catch(Exception e) {
              CreateAndShowDialog (e, "Error");
          }
      }
  
      private async void Initialize()
      {
          RunOnUiThread(() =&gt; statusText.Text = "Authenticating...");
          await Authenticate();
  
          RunOnUiThread (() =&gt; statusText.Text = "Syncing...");
          await InitLocalStoreAsync();
  
          MoveToMainActivity();
      }
  
      private async Task Authenticate()
      {
          try
          {
              user = await client.LoginAsync(this, MobileServiceAuthenticationProvider.Google);
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex.ToString());
          }
      }
  
      private async Task InitLocalStoreAsync()
      {
          // new code to initialize the SQLite store
          string path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), localDbFilename);
  
          if (!File.Exists(path))
          {
              File.Create(path).Dispose();
          }
  
          var store = new MobileServiceSQLiteStore(path);
          store.DefineTable&lt;ToDoItem&gt;();
  
          // Uses the default conflict handler, which fails on conflict
          // To use a different conflict handler, pass a parameter to InitializeAsync. For more details, see http://go.microsoft.com/fwlink/?LinkId=521416
          await client.SyncContext.InitializeAsync(store);
      }
  </code></pre>
  
  <p>How do I restructure this so that I don't get any screen flashes?</p>