Obtaining data from activities

We may want to show the user a new screen in order to obtain some feedback before the current task can be completed.

How to do it...

Starting an activity so that we can get feedback is done through the StartActivityForResult() method:

  1. First, we start the activity using the StartActivityForResult() method:
    var intent = new Intent(this, typeof(ResultsActivity));
    StartActivityForResult(intent, 1234);
  2. Then, when that activity is finished, we handle the result in the OnActivityResult() method:
    protected override void OnActivityResult( int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (requestCode == 1234) { if (resultCode == Result.Ok) { var value = data.GetStringExtra ...

Get Xamarin Mobile Development for Android Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.