Different methods of moving data between screens. (TinyDB vs Start Value)

What are the pros and cons of moving data between screen using either TinyDB and start value?

I have around 3 screens and multiple virtual screens within them, a main screen where a list of data is retrieved every time the app is started. When navigating between screen, I have a variable that tracks last virtual screen that was on a particular page. When using tinyDB for my application, I have trouble figuring out an algorithm to clear TinyDB everytime the app is restarted.

Based on my limited experience, research and testing done, seem like start values are simpler to work with as lesser codes are used and way easier to clear data when the app is closed.

What about
TDBClear in the Screen1.Initiialize event handler?

Really? Seems it depends on how your app exits and what you mean by 'closed', Seems a required Button would be a great place to clear the data prior to finishing your 'patient' session and how your logic works. Be tidy.

Pros/Cons ... to me, TinyDB and namespaces is easier to handle coding wise but then everyone will have their preferred method. Use what you are comfortable with.

1 Like

Thanks @SteveJG for the quick response and tips.

In my case, close can mean properly exit or force stop.

Explain what exactly the goal of your approach is.
What exactly should be saved when and where and when and where should it be available again?

1 Like

The goal is, if I were to return to my main screen from other screen, i keep my data, else if i restart the app either due to force stop or properly exiting, then clear all the data. Just read that apparently initialize event on AI2 companion does not work as in the final APK, due to the initialize event being triggered every time I go back to the main screen.

I think I have my solution now, but feel free to chip in any tips you might have.
Thanks for the help all.

It depends on how you switch screens.

1 Like

Pls try like this whether works or not

In screen1 init try to call the get value (use if then alone,)

If the get value is empty
Then 
call tinydb to clear all

In other screens, if you want to go to S1 then pls use any value in start value

After this logic set the global variable to call the tinydb, if not found use empty string or create empty list depending upon what you are adding the items into the tinydb

As I can see, you have received enough suggestions. Just, to refresh, you are to have three buckets in you tinyDB, Screen1,Screen2, and Screen3, when you open your app very first time, clean buckets with "".
Just before you jump to other screen(let say Screen2), update the bucket corresponding to current screen, Screen1="MyHorizontalArrangement1",

Now, you decide to switch to Screen3, just before going to Screen3, change Screen2="MyHorizontalArrangement5".

Now, you decide to switch to Screen1, just before going to Screen1, change Screen3="MyHorizontalArrangement007".

Now, you decide to switch to Screen3 from being in screen1, just before going to Screen3, change Screen1="MyHorizontalArrangement004".

Each time, bucket will have one value or empty.

As, SteveJG said, it is your logic, when you do clean desk, before leaving office OR when you join/come/start work next day.

1 Like

Correct me if I'm wrong. I have tried this and the screen initialize event will be triggered first before the other screen closed event, hence the start value can only be access during after the screen initialize event. However I have only done this test on AI2 companion and I read that is one of the limitations on that.

I used the close screen function when returning from screen2 to screen1, am unsure is that the right way in this case, as according to @Anke, the method of switching screens matters, am not sure how.

the recommended method of switching screens is the manager screen method

you can read the notes there about companion app limitations

Taifun

1 Like

Tried like this and test the apk. Initi opening of app , label says, fresh open in screen1, if i come from screen2 label says what i stored in the tinydb of S2


If app open first or after the crash i am sure this start value will be none. Start value can be accessible until the app is live. Once it come from complete kill this value will nullify so i tried like this

1 Like

Alrighty, seem like I have all the info I need and have done a working example for now.

Thank you to @Anke @Spicy_Topics @Taifun @SteveJG and @RamNaresh for your help.

Now how do I close this thread? Or do I leave it as is?

1 Like

The only way to close the thread is to mark a comment as accepted answer. Since you have used information from multiple replies, and this is tagged as "General Discussion", I would leave it as is. Besides, if you have any other questions relating to this topic, you won't need to start a new thread.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.