0

I would like to know if there is a reference document that carefully lists all AppCompatActivity overrides that may be declared async.

For instance, I could mark:

protected override void OnCreate(Android.OS.Bundle savedInstanceState)

async like this:

protected override async void OnCreate(Android.OS.Bundle savedInstanceState)

As you can see I'm using async void, not async Task. So Because it is probably the top level async method, it is marked async void.

If there is something out there that goes beyond the scope of AppCompatActivity, that would be a must.

  • Events and LifeCycle methods are an exception to the above rule as you do not have control over them, these methods are defaults basically if you want I can add a full-fledged if this does not satisfy you – FreakyAli May 28 '19 at 09:42
  • why not adding an answer? –  May 28 '19 at 16:25

1 Answers1

0

It's quite common to make event handlers async void but in this case it's possible that OnResume runs before the Activity is fully initialised in async OnCreate . Since we have no control over whether OnCreate is awaited, the only proper solution is to move long running tasks out with initialisation which is probably a good idea anyway.

Cherry Bu - MSFT
  • 10,160
  • 1
  • 10
  • 16