Handle Activity Finishing Event In Xamarin.Android

淺唱寂寞╮ 提交于 2019-12-11 22:13:42

问题


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



来源:https://stackoverflow.com/questions/26096579/handle-activity-finishing-event-in-xamarin-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!