How to run a piece of code only at the start of the app?

I have come up with a solution,but it has some flaws and I would like to get it cleared!

The idea is to display a welcome message (sort of) when the user launches the app, but not run that piece of code when switching back from another screen.
The timers used are disabled by default and TimeralwaysFires is checked .

with the logic below, I was able to verify that it works in development mode(with AI companion) but when built into an application, I am having following issues:

  1. The label1 that is supposed to display a string every time the screen1 is initialised runs only once.
  2. the label that is supposed to display the welcome message doesn’t work when I cleared the recent apps and reopen it afresh. (but works once ,i.e when the app is re-launched after pressing back button to quit the application)

Relevant files are attached below.

Thanks,
Somu.

app_launc_code.aia (5.6 KB)

Hi Somasundharam_Sampat

Timer always fires is rarely required, except for games. It must be false if you switch ‘Real’ Screens. To not display something again, simply use a boolean variable. If not using Virtual Screens, store the variable in TinyDb and check it when Screen1 is displayed. For Example:

Note though, the message will not be shown the next time (minute - years) the App is run on the same device. If you want to annoy your Users and show the message every time they open the App, record the last time the message was displayed, calculate elapsed time and decide then if the message should/should not be displayed.

Hi @ChrisWard,

The reason I would like to display the welcome message is so that I can retrieve some data from firebase and ready for display when the user clicks a button to view the value, I don’t know how much time does it take. but I thought this way it’ll look smooth.

Also, I have chalked up something similar to your suggestion (just that my blocks wud display a message everytime the user launches the app) I didn’t think abt the possibility that the user wud launch the app frequently between a short period of time, so thanks for pointing that out, it’ll be tiring for users to see the same msg over and over again :blush:

In the blocks that I have attached, the another task is analogous to firebase getvalue block, so my problem was when I built this into an app, the another task timer was not working when i returned from screen2 (but in dev mode works every time when i land in screen1)

Also. If you see my blocks, the logic that I used was, when backpressing I store the value of app launch status to true in tinyDB, so that the next time the user launches the app it’ll show the app startup message which is what happens when i backpress to quit, whereas if I quit by clearing the recent apps, on relaunching the app, the startup message doesn’t show, which kind of make sense to me because I think the value of app launch status variable(tinyDB) is still false (as set last in the screen1.initialize event)

Hoping that I’ve convinced you of the need for startup message everytime, I would like to know how could I work around the above said problems that occur only after building the app !!! :grin:

Thanks,
Somu

Right, it is simple if you think of individual Screens as being individual Apps that know nothing about each other - because multi-screen apps are effectively that.

Only the most simple Apps should use Multi-Screen if more than one screen is absolutely necessary -notice how many commercial Apps tend to have one longer screen instead? For all multi-screen Apps, Virtual Screens save a lot of developer grief, code and bugs/typos.

Clock Timers rely on system resources. Never switch on a timer until it is actually required. Switch it off when not required. Before you leave a Screen, your code must switch off all timers on that Screen.

If the User clears recent Apps, or the Smartphone battery runs to zero, you would in those circumstances require a ‘full’ start up of the App wouldn’t you? So it’s not straight forward - either the App decides silently, based on something like elapsed time, or the App asks the User what to do.

1 Like