Data transmission

Greatings,

I came across an issue where a database entry can not be sent from one screen to another.
Using the sceen .initialize state can't be used with the database as it is still being initialized in this state.

If a hasInitialized state could be added to a screen with the next ai update that could help.

You could set the value of a variable as the last action of screen initialise or other event on initialisation, then test for this, using a clock timer to activate your next process.

The clock is a very good idea but it a hacky one. The prefered method is states but even they use some timing. Thank you very much.

Hello Almario

What database are you using? Is it in the Cloud or on the device? When you say 'a database entry' do you mean one specific value?

If the 'another' screen has access to the database, perform that access via a Procedure, called as the last entry in Screen Initialize.

Alternatively, if that data is input on one screen and then the 'another screen' is opened, you could share the data via 'open another screen with start value'.

Finally, and usually the best solution, use Virtual Screens:

When we define virtual screens, we use one 'real' App Inventor Screen (most often Screen1). Screen-sized Vertical Arrangements on it are displayed/hidden as required - they are the Virtual Screens. This is generally a better approach for multi-screen Apps, they share data without having to "pass" it between screens and it also reduces code duplication, making the App more efficient and the code easier to follow if you have to return to it at a later date.

So, instead of separate "houses", virtual screens are "rooms" of the same "house".

1 Like

Hey there Chris,

It's a cloud hosted db. I have a few images I hope the blocks explain the main idea. I keep having a state issue when the global variables are being set in the db GotValue state.


Hi Almario

In Screen1, why is the secretData value set to a tag? Indeed, since Screen2 is connecting to the DB, it is not necessary for Screen1 to do so? Just use the TextBox text as the start value when opening Screen2? Yet then the question has to be asked - why not just do everything on Screen1?

Also, the open another screen block is in the wrong place. Move it to the gotValue event

Hi Almario

So, assuming you use a separate master App to enter User IDs and Passes (Can allow Users to do this too if required), Here is the gist of your Blocks using Virtual Screens.

When the App is run, a Login dialog is displayed. If the User enters the correct credentials, the Login dialog is hidden and App Screen (Virtual Screen1) is displayed.

DatabaseLogin.aia (3.3 KB)

Good day,

A combination of your replies led to a solution for now. Thank you.

Why not share your solution so that others may learn...?

1 Like