Today we're announcing our initial effort to make Activities in Android more friendly for .NET Developers. For now, we are calling it the ActivityController .

ActivityController is meant to act as a sort of replacement/proxy for AppCompatActivity . Currently, its primary purpose is to enable the use of async/await when using StartActivityForResult in an Activity , with the ability to survive the unpredictable lifecycle of activities on Android.

We're looking for dialog, feedback, suggestions, and contributions around this concept. The source code for the project can be found on GitHub here: https://github.com/xamarin/android-activity-controller

The boilerplate for using ActivityController looks something like this:

[Activity(MainLauncher = true, Label = "Your Activity", Theme = "@style/Theme.AppCompat")] public class MainActivity : ControllerActivity<MainActivity.MainController> { public class MainController : ActivityController { protected override void OnCreate(Android.OS.Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.FirstLayout); // Your code } } }

Inside your ActivityController you will see the new method StartActivityForResultAsync (Intent intent) . You can await this. We've also added a few helper methods which will construct the appropriate Intent and call StartActivityForResultAsync<TResult> for you, returning a TResult with relevantly typed results. This includes:

PickContactAsync

PickPhotoAsync

TakePhotoAsync

PickVideoAsync

TakeVideoAsync

There is a prerelease package on NuGet. Please try it out!

If you have comments, feedback, or suggestions, please create a new GitHub Issue to discuss.