问题描述
在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)
/ pre>
{
base.OnActivityResult(requestCode,resultCode,data);
if(resultCode == Result.Ok){
//在A
中执行任何需要完成的任务
}
这一切都记录在
Is there anything similar to
FormClosingEvent
in Xamarin.android?I have two activities -
A
andB
.B
is saving some data and is called fromA
on button click. I have list of data inA
and want to automatically update it afterB
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 mannervar 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处理活动整理事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!