Java.IO.ISerializable Xamarin
android, c#, java, xamarin, xamarin.android
Solution
Well you could solve it easily by just serializing `Xamarin.Facebook.Model.IGraphUser` with any serializer which produces `string` or `byte[]`. For example if you use Newtonsoft's Json.NET component your code would look something like that:
Xamarin.Facebook.Model.IGraphUser fbUser;
var fbUserSerialized = JsonConvert.SerializeObject (fbUser);
intent.PutExtra ("fbUser");
And to deserialize:
if (Intent.HasExtra ("fbUser")) {
var fbUserSerialized = Intent.GetStringExtra ("fbUser");
var fbUser = JsonConvert.DeserializeObject<Xamarin.Facebook.Model.IGraphUser>(fbUserSerialized);
}
Problem
I'm trying to pass object in Android using Iserializable, but it return me "Unable to activate instance of type from native handle" exception. Below are my codes. [FBUserParcel.cs] ``` using System; using Android.OS; using PlayCardLeh.Helpers; namespace PlayCardLeh.Android { public class FBUserParcel:Java.Lang.Object, Java.IO.ISerializable { Xamarin.Facebook.Model.IGraphUser fbUser; public FBUserParcel (Xamarin.Facebook.Model.IGraphUser user) { fbUser = user; } } } ``` [MainActivity.cs] ``` private async Task FindFBUser(Xamarin.Facebook.Model.IGraphUser user) { if (user != null) { Console.WriteLine ("GOT USER: " + user.Name); try { var t = await User.FindUserWithFBID (user); } catch(NotFound NotFound) { RunOnUiThread (() => { Intent i = new Intent (this,typeof (RegisterActivity)); FBUserParcel u = new FBUserParcel(user); StartActivity (i); }); } } else Console.WriteLine ("Failed to get 'me'!"); } ``` RegisterActivity.cs ``` protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.Register); if (Intent.HasExtra ("fbUser")) { var u = Intent.Extras; u.GetSerializable ("fbUser"); } } ``` The exception happen at "u.GetSerializable ("fbUser");". Sorry I'm kinda new to Xamarin, anyone have exprience with using Iserializable? What did I missed out in "FBUserParcel.cs" ?? Thanks Mug4n for sharing a link that discuss about the same issue. http://forums.xamarin.com/discussion/451/communicate-with-iserializable