Switch screens correctly - 2 methods

Since questions about this have been coming up again and again for years (actually right from the start), here is a short tutorial with a test app. Test it with Companion & with the APK.

switchScreensCorrectly.aia (10.0 KB)

Blocks - Screen1

Blocks - Screen2

There are basically two methods how screens can be switched correctly:

  1. Screen1 remains open after switching to another screen. All other screens are closed when you switch to another screen. This means that at most two screens are open at the same time. If another screen is then closed, Screen1 comes to the foreground again (since it wasn't closed). Then only one sceen is open.
  2. Each screen (including Screen1) is closed when another screen is opened. This means that only one screen is open at the same time.

Which method is preferred depends on various considerations - for example:
Sometimes it is required that Screen1 be reinitialized after returning from another screen. This is only possible with method 2. Otherwise, Screen1 would be reopened, eventually causing a memory issue and crashing the app.

On the other hand, Screen1 may be very extensive (it contains many blocks, procedures, extensions, etc.) so that initialization takes some time. In this case, it would make more sense not to close (and reopen) Screen1, but only by closing another screen to get back there (i.e. to Screen1).

Finally, a simple test app using both methods, only with the necessary blocks to switch 3 screens:
switch3ScreensSimple.aia (5.9 KB)

Blocks - Screen1 & 2


Screen2 (and accordingly Screen3):


Thank you @Anke

And for those, who are a little bit overwhelmed and are asking do we really need all those blocks to switch screens, see a simple use of the 2 methods here


See also tip 1 here


1 Like

Also, a simple screen switching example:

TestNestingScreens.aia (15.5 KB)

Uses the two methods above, so will only work when compiled as apk.

Of course not. The app is for demonstration purposes only. I will post the (exclusively) necessary blocks for both mothods separately again. Is that actually still necessary since I've explained everything you need to know about it in detail?

(added to FAQ)

1 Like

Hi. I have created an app, and I am testing it on an android device using the AI2 companion. However, after playing the app for about 5 minutes, it starts to "slow down." The gifs in the app go really slow and it takes forever to load from one screen to the next. I have reduced my gifs and other images to the least amount/smallest size that will still make my app as I want it to be. I have also deleted unnecessary code. Because I am using the KIO4_AniGif2 extension to play my gifs, i made sure to stop all gifs before switching screens.
I am convinced that the problem must be that i am leaving screens open. At first I was using the open screen with start value block. Then I tried @Anke method for having only one screen open at a time. This did not work because as I switched screens in the time it took to load I saw a brief flash of (not the screen I was coming from) but the previous screen. Then I tried the Tribblehunter method that @Taifun suggested, but this time when I switched screens, I briefly saw the screen I was attempting to switch to, but then the app switched right back to the screen I came from.
Is there any other way to make sure ALL screens are closed except the one that I am on?

I have already mentioned this method. So post your AIA where this method was used and the problem still occurs.

Hi, sorry for the late reply. Here is a video of what happens in the AI2 Companion. I am using @Anke your method listed above to switch screens. After running the app for about 5 minutes, it still begins to "slow down". Eventually after becoming really slow, it gives me a connection error and the session on the companion ends. Occasionally (as in the video) I get a out of memory error instead of the connection error.


Post your aia.
(And please show screenshots, images / blocks in high quality. See also here.)

Hi again. I decided to try testing my app by downloading the apk onto my android device and then running it instead of using the AI companion. This time the app did not slow down or give me any errors (I was still using @Anke your method to switch screens). So it must have been the AI companion because with the apk everything was perfect. Thank you for your help and for the switching screens method!

1 Like

thanks for the aia, It works, but I cannot find a "call openscreen" (also has "chbText" option?) block to use in another app. It's not under Screen1, and I've looked elsewhere. (I also Googled chb and variations alng wih app inventor.). I must be missing something obvious.

call openscreen

Which aia are you talking about?


Where is it?
EDIT: Ah, got it

no 3 in it

These are Procedures.

right. they appear in the menu in switchScreensCorrectly.aia but not in a standard app (my new app). do I import your library or something? Sorry if I'm missing something obvious

You must create these procedures yourself: