Passing Custom Object Between Android Activities In C#
Solution 1:
To coat tail on the servicestack.text solution, you can just download the android DLL's and reference them into your solution. You can use this and add it to your solution, build it separately, as alternatives. https://github.com/ServiceStack/ServiceStack.Text/tree/master/src/ServiceStack.Text.Android
Also I use a couple of methods to convert items back and forth that may be helpful, try
staticpublicstringToJSON(thisobject item)
{
var myval = JsonSerializer.SerializeToString(item);
return myval;
}
staticpublic T FromJSON<T>(string code)
{
var item = JsonSerializer.DeserializeFromString<T>(code);
return item;
}
Solution 2:
There's an article on using IParcelable in Xamarin here.
Personally, I've always just serialised to JSON, passed a string extra and deserialised it on the other end.
If you're using ServiceStack.Text, which I like, you can do something like this:
intent.PutExtra("SelectedItemId", JsonSerializer.SerializeToString(selectedInsurance));
And on the other end:
var insurance =JsonSerializer.DeserializeFromString<InsuranceReminderBO>(Intent.GetStringExtra("SelectedItemId"))
No need to implement Java.Lang.Object, Java.IO.ISerializable
Solution 3:
After doing a lot of search on Google finally i found a solution here.
Basically I used StartActivity(intent);
Post a Comment for "Passing Custom Object Between Android Activities In C#"