Xamarin Android 页面间传值方法:
父页面:
Intent intent = new Intent(this, typeof(ChildPage));
intent.PutExtra("STID", 3);
StartActivityForResult(intent, 1);
子页面接收传值:
var tid = Intent.GetStringExtra("STID");
if (string.IsNullOrEmpty(tid))
//...
子页面发送返回值:
Intent intent = new Intent();
intent.PutExtra("userPhoneNumber", userPhonNumber);
SetResult(Result.Ok, intent);
Finish();
父页面在OnActivityResult重写方法中接收返回值:
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
{
if ((requestCode == 1&& resultCode == Result.Ok)
{
if (data == null) return;
var userPhoneNumber = data.GetStringExtra("userPhoneNumber");
if (string.IsNullOrEmpty(userPhoneNumber))
//...
}
}
网友评论