protected override async void OnCreate(Bundle savedInstanceState) { _destroyCancellationSource?.Dispose(); _destroyCancellationSource = new CancellationTokenSource(); var localDestroyCancellationSource = _destroyCancellationSource; base.OnCreate(savedInstanceState); _persistedDataFragment = (PersistedDataFragment)SupportFragmentManager.FindFragmentByTag(PersistedDataFragmentTag); if (_persistedDataFragment == null) { _persistedDataFragment = new PersistedDataFragment(ApplicationContext); SupportFragmentManager .BeginTransaction() .Add(_persistedDataFragment, PersistedDataFragmentTag) .Commit(); } else { _persistedDataFragment.ApplicationContext = ApplicationContext; } // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); var progressBar = FindViewById <ProgressBar>(Resource.Id.MainProgressBar); var progressText = FindViewById <TextView>(Resource.Id.MainProgressText); Account account; try { progressText.Text = GetString(Resource.String.RetrievingUserProfile); await _persistedDataFragment.GetOrCreateUserProfileAsync(this, localDestroyCancellationSource.Token); if (localDestroyCancellationSource.IsCancellationRequested) { return; } progressText.Text = GetString(Resource.String.RetrievingAccountInformation); account = await _persistedDataFragment.GetAccountAsync(this, localDestroyCancellationSource.Token); } catch (Exception ex) { if (!localDestroyCancellationSource.IsCancellationRequested) { var alert = new AlertDialog.Builder(this).Create(); alert.SetMessage(ex.Message); alert.DismissEvent += (sender, e) => { Finish(); }; alert.Show(); } return; } if (localDestroyCancellationSource.IsCancellationRequested) { return; } if (account?.Id == null) { var intent = new Intent(this, typeof(NoAccountActivity)); StartActivity(intent); Finish(); return; } progressBar.Visibility = ViewStates.Gone; progressText.Visibility = ViewStates.Gone; Title = account.Name; InitializeViewPager(); InitializeTabs(savedInstanceState); }
public override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); _persistedDataFragment = (PersistedDataFragment)FragmentManager.FindFragmentByTag(MainActivity.PersistedDataFragmentTag); }