Thursday, July 12, 2012

[android-developers] Re: Parameters "passed" using static fields of application become null sometimes

So the system is trying to recover the activity after the VM shutted down, and if I serialize/persist the data it will be restarted correctly and the app will not crash?

I thought VM crash would be the end of everything and the app would crash inevitably after it. I thought that these errors where just some kind of post traumatic disorder, and if i fix them the app will crash anways... that's why I was looking how to fix the VM crash instead of the null pointer.

But you say, although the VM crashes, if the data can be recovered everything will run normally, is that right? Then I'll start immediatly to serialize all the parameters.


On Thursday, July 12, 2012 8:24:46 PM UTC+2, Nobu Games wrote:
Seriously, instead of waiting for a reply that explains to you all different scenarios when and how the VM crashes, you should start coding a solution the clean way and either pass over that data via Intent, store it in some SharedPreferences object or in a database or something.

You don't necessarily need to implement Parcelable (which is indeed a pain in the backside). If your data classes carry just some serializable members then add the Serializable interface to them. Serializable objects can also be bundled as Intent extras via putSerializable(). It's pretty much effortless to use.

If your data classes contain contexts or other non-serializable members, declare these members as transient:

private transient Context mContext;

And on de-serialization in your next Activity you can assign these members again.

Java Collections (like your String List in above example) are serializable by the way.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate