Handle Activity Finishing Event In Xamarin.Android

2019-08-28 22:57发布

问题:

Is there anything similar to FormClosingEvent in Xamarin.android?

I have two activities - A and B. B is saving some data and is called from A on button click. I have list of data in A and want to automatically update it after B activity is finished.

Any suggestions how to do it?

回答1:

It sounds like you want to use StartActivityForResult with Activity A starting activity B in the following manner

var myIntent = new Intent (this, typeof(ActivityB));
StartActivityForResult (myIntent, 0);

ActivityA should also then override OnActivityResult waiting to respond to activity B's response code and update as necessary.

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
  base.OnActivityResult(requestCode, resultCode, data);
  if (resultCode == Result.Ok) {
     // Do whatever needs to be done in A 
  }
}

This is all documented quite well in Xamarin's Android documentation