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:
First, we start the activity using the
StartActivityForResult()
method:var intent = new Intent(this, typeof(ResultsActivity)); StartActivityForResult(intent, 1234);
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 ("Key"); } else { // canceled } } }
In the new activity, we specify the result data to be passed back to the calling activity through the
SetResult()
method:var result = new Intent(); result.PutExtra("Key", "Some...