3 ms·
It's hard to pass objects like that because it's a terrible idea. If you can't serialize the object then your state isn't stored and you'll possibly lose that
by jayd16 10y ago
It's hard to pass objects like that because it's a terrible idea. If you can't serialize the object then your state isn't stored and you'll possibly lose that object on a screen rotation and activity restart.
- sidlls 10y agoIt's a pretty terrible design to couple activity state to the physical orientation of the device.
- jschwartzi 10y agoTo be fair, there may have been really good reasons for it back when Android devices had 500 Mhz single-core CPUs with 32 or 64 Megabytes of RAM.
- AstralStorm 10y agoStill good reasons when a web browser eats 500 MB.
- jonas21 10y agoYou can always handle the orientation change manually if you want to. But if you don't want to bother, restarting the Activity seems like a reasonable default.
- jayd16 10y agoNo, you don't understand. The state is serialized and stored. You might navigate away or pop into a windowed state. These things might rebuild your activity and the idea is your state should be serializable. The idea is every activity can be restarted outside of your control and your state should be fully storable.
- sidlls 10y agoNo, I understand the Android Activity lifecycle quite well. I think it has severe flaws from a design perspective.
- AstralStorm 10y agoNot from design, no. Design is pretty sound. It has implementation issues - you get to use a crusty ContentProvider or manually serialize everything into also crusty Bundle. Then you have that separate SharedPreferences thing. Or you can do it on your own, typically more cleanly, with an object database. Instead it would be often fine if it just took a Java Serializable and ran with it, just call you back so that you can read all the state and redo whatever you need to redo. Likewise IPC with Intents is pretty crusty as is with Binder, though bit less with the latter.
- hota_mazi 10y agoHow would you do it?