Forum Xamarin.Android


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Serialize an instance of a Fragment

So I'm using the Newtonsoft JSON serializer..I want to serialize a fragment to store it in a sql database. The fragment is inheriting from Android.Support.V4.App.Fragment and at the point where I'm trying to serialize, the object has already been created and the layout was inflated as well. I'm also relatively new to developing for Android and C# and .NET, so I could be making major blunders elsewhere.

The class is a bit too big to post here, it holds a lot of other objects such as Buttons, ImageViews and some other data types. All the fields are private but I've also tried this by making public properties for them. I've tried with and without [Serializable] although I don't think that has anything to do with json.

So the event that triggers this eventually tries to run:

var test = JsonConvert.SerializeObject(mMemoriesFragment);
Console.WriteLine("DATA: " + test.Length);

and each time the value is returned 2, which is just "{}"

Sign In or Register to comment.