本文介绍了在Xamarin.Android处理活动整理事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xamarin.android中有什么类似于 FormClosingEvent



我有两个活动 - A B B 正在保存一些数据,并从按钮点击的 A 中调用。我有 A 中的数据列表,并希望在 B 活动结束后自动更新。



任何建议如何做?

解决方案

听起来你想要使用 StartActivityForResult 与活动A以以下方式启动活动B

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

ActivityA还应该覆盖 OnActivityResult 等待响应活动B的响应代码并根据需要进行更新。

  protected override void OnActivityResult(int requestCode,Result resultCode,Intent data)
{
base.OnActivityResult(requestCode,resultCode,data);
if(resultCode == Result.Ok){
//在A
中执行任何需要完成的任务
}
/ pre>

这一切都记录在


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?

解决方案

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

这篇关于在Xamarin.Android处理活动整理事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 22:29