Android Question [Solved] Do I need save state and settings in B4XPages?

asales

Expert
Licensed User
Longtime User
In my activities projects I use this class StataManager (in pause/resume) to save and load the contents of the edits, spinners, etc.
It is usefull to restore date when the user exits in an activity different the main and back after a while.

In the link @Erel recommends: "Use B4XPages + KVS2 instead".

In my new projects I use B4XPages.

Do I still need save the contents of the edits, etc. in the KVS2, as I do with the StateManager?
 
Solution
12. The pages context will not be paused or destroyed, until the process itself is killed.
So no, when you go back, it is as you've never left.

William Lancee

Well-Known Member
Licensed User
Longtime User
12. The pages context will not be paused or destroyed, until the process itself is killed.
So no, when you go back, it is as you've never left.
 
Upvote 2
Solution

MicroDrie

Well-Known Member
Licensed User
As asales already wrote
So no, when you go back, it is as you've never left.
However if you exit and close your B4XPages program, or you release one or more to B4XPage(s) your lose information. so there isn't one but more answers to your question:

Do I still need save the contents of the edits, etc. in the KVS2, as I do with the StateManager?
  1. No if you do not remove the B4Xpage of exit and close the program

  2. Maybe Yes to store the information in KVS2 if you remove a B4XPage while still running the rest of the program

  3. Yes, if you close the program and want to continue from where you left off when you closed the program.
In the link @Erel recommends: "Use B4XPages + KVS2 instead".
As always, Erel's recommends short answer is the best solution (though not always obvious to everyone why) because it leaves open all the possibilities described above.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
To be clear, it was me who said that
William Lancee said:
So no, when you go back, it is as you've never left.
@MicroDrie
2. Closing a B4XPage does not destroy the page (which is just an instance of a class), and keeps its data intact.
3. I quoted @Erel: 'The pages context will not be paused or destroyed, until the process itself is killed.'

Now what kills a process is the OS, and how and when it does so is complicated and varies with versions of Android.
Some scenarios:
1. A crash
2. ExitApplication when there is only one Activity (at least in earlier versions of Android)
3. User telling the OS to remove the app, using the tools menu
4. other situations depending on Android version

As expected, all of these require critical data and app state to be saved (possibly in a KVS2 object/file).
But your App may not know when that will happen! So save critical data when it is created, not when you exit.
 
Upvote 0
Top