Wish Simplified state management

Troberg

Well-Known Member
Licensed User
Longtime User
One of the pitfalls in all Android development is state management when the activity is paused. It's not very hard, but it has some devious pitfalls. Not only that saving and loading state is, while not hard, a bit of work and quite prone to mistakes (because one tends to turn off the brain when doing routine tasks, especially when they are not an integral part of the problem you are actually working on).

So, in the spirit of RAD tools, I would put forward this suggestion:

Much like we now have Process_Globals and Globals, I'd like to have two more variants, called, for example Persistent_Process_Globals and Persistent_Globals. These would work exactly like their current counterparts, except that their state would be maintained automatically, behind the curtains. B4A would simply save and load them as needed, and the programmer wouldn't have to bother about how and when it's done.

It wouldn't break existing programs, as the old Process_Globals and Globals would work exactly as before.

It would lower the newbie threshold, and would let experienced programmers spend more time being productive and less time doing "paperwork". More RAD, more focus on the task at hand.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is an interesting idea. As I see it Persistent_Globals is not really useful. However Persistent_Process_Globals can be useful.
Remember that many objects cannot be simply persisted. For example you cannot persist a database connection.

KeyValueStore class can be used for this purpose. It allows you to save / restore objects in a very simple way.
 

Troberg

Well-Known Member
Licensed User
Longtime User
I agree that Persistent_Globals wasn't really thought through.

As I said, it's not that hard to do the persistance manually, but, especially in a dev environment intended to be RAD, why should I?

As for objects that cannot be meaningfully persisted, I don't see that as a big problem, as they usually aren't objects one would want to persist anyway. Just raise an error if one tries to add them to that section.
 
Top