Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monodroid putting parcelable objects to bundle

So I've been struggling with putting some values into a bundle in my overrided OnSaveInstanceState. I need so save some class objects on activity restart, meaning they have to be parcelable, which seem to be impossible to implement for Monodroid?

Source : http://docs.xamarin.com/android/about/limitations

What can i do to save these class objects in to the bundle without parcelable? I load data from a server, and I don't wish to do that again for example on a user rotation, which once again calls the OnCreate method. Therefore it would be nice to have them saved, which saves the server some pressure on occasional rotations and such.

like image 563
Lucas Arrefelt Avatar asked Mar 20 '12 13:03

Lucas Arrefelt


People also ask

Are bundles Parcelable?

Bundle is a container for named values of types standard for android (including Parcelable ), which is used to pass data between activies, fragments and other android app entites.

When to use Parcelable?

Parcelable and Bundle objects are intended to be used across process boundaries such as with IPC/Binder transactions, between activities with intents, and to store transient state across configuration changes.

How do I send a Parcelable intent?

Suppose you have a class Foo implements Parcelable properly, to put it into Intent in an Activity: Intent intent = new Intent(getBaseContext(), NextActivity. class); Foo foo = new Foo(); intent. putExtra("foo ", foo); startActivity(intent);

How Parcelable works in Android?

In simple terms Parcelable is used to send a whole object of a model class to another page. In your code this is in the model and it is storing int value size to Parcelable object to send and retrieve in other activity.


1 Answers

The originally accepted answer for this question, while true at the time it was answered, is no longer the case.

I had originally implemented the above suggestion and then later on through more searching found this:

http://dan.clarke.name/2012/09/implementing-iparcelable-in-mono-for-android/

The feature is now supported and the above link is a great resource on how to implement it.

like image 167
DavidR Avatar answered Nov 14 '22 22:11

DavidR