Java.IO.ISerializable Xamarin

I'm trying to pass an object to Android using Iserializable, but it returns me the exception "Unable to activate instance of type from built-in descriptor".

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");

    }
}

An exception occurs in "u.GetSerializable (" fbUser ");". Sorry, I'm new to Xamarin, who has experience using Iserializable? What did I miss in "FBUserParcel.cs" ??

Thanks to Mug4n for sharing the links discussed on the same issue. http://forums.xamarin.com/discussion/451/communicate-with-iserializable

+4
source share
1

, , Xamarin.Facebook.Model.IGraphUser , string byte[].
, Newtonsoft Json.NET, :

Xamarin.Facebook.Model.IGraphUser fbUser;
var fbUserSerialized = JsonConvert.SerializeObject (fbUser);
intent.PutExtra ("fbUser");

:

if (Intent.HasExtra ("fbUser")) {
    var fbUserSerialized = Intent.GetStringExtra ("fbUser");
    var fbUser = JsonConvert.DeserializeObject<Xamarin.Facebook.Model.IGraphUser>(fbUserSerialized);
}
+6

All Articles