On Sun, Sep 4, 2022 at 9:01 AM Barbarur wrote:
> OK, I think I got it.
> If data is still on memory, on_resume() would be called and app continues performing as normal.
> If data is not on memory, on_start() would be called were we can load data we saved during on_pause().
Did you verify that in practice?
> Is there any best practices on how to handle this data? This is so far what I have in mind:
I told you in the first reply, this is described in the docs:
https://kivy.org/doc/stable/api-kivy.app.html?highlight=on_resume#pause-mode
> on_pause()
> Save important data on the DB.
> Save temporal data of the app status on a file. I might use a simple .txt file.
Yes, if you use DB then you need to store data, flush it, and close
it. Just like on_stop(). Because there is no guarantee that
application will work after that.
> on_resume()
> Delete the file, as app status data is still on memory and app has been resumed correctly.
>
> on_start()
> If .txt file exist (meaning the app is been open), load with the app status data from the .txt
> If .txt file doesn't exist (meaning the app is freshly opening), no action taken and continue with the normal flow of the app.
>
> Does doing something like this make sense?
There is a "Config" infrastructure provided in Kivy. It uses plaintext
variable = value syntax (like *.ini file). This is also described in
the docs and my first answer. There are "sections" in that config, you
can have "state" section.
It is good to understand and use "Finite State Machine" model. Your
device and/or application has predefined states it can be in, and
transitions between those states. This way you always know what state
application is, and you can control allowed/forbidden transitions
between these states. For instance you have a web shop, you wan to
have states: select item, add item, add shipping info, payment,
shipment, shipment tracking, order completed, transitions between
these states can co only go one after, and it it forbidden to jump
over to shipment when payment is not completed (i.e. from shipping
info state). By storing state in the config file user will always come
back to the place where he/she was last time.
https://www.freecodecamp.org/news/state-machines-basics-of-computer-science-d42855debc66/