Hacker News new | past | comments | ask | show | jobs | submit login

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.



It's a pretty terrible design to couple activity state to the physical orientation of the device.


No, 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.


No, I understand the Android Activity lifecycle quite well. I think it has severe flaws from a design perspective.


Not 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.


To 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.


Still good reasons when a web browser eats 500 MB.


You 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.


How would you do it?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: