Opening another screen AND closing the current one

Is immediately closing the parent screen necessary? Is it good practice? Does this
avoid memory leaks?

If I'm doing this from Screen1 and when I come back from the child, is
there a screen to return to if I'd just closed it? Will the parent be recreated?

Confused, I haven't seen this usage before.

Yes, to release resourses associated with it. Else, it can cause memory issue.

Building Apps with many screens

It is not necessary... the recommend method to switch screens is the manager screen method

Taifun

Thanks for the link, bit it does not address my specific question. I've been using virtual and regular screens for years, but never came across the above advice. I was hoping for a technical explanation, as I'm somewhat familiar with Android Activity lifecycle...

Thanks, Manager Screen is very elegant and clean.

Technically speaking, starting app is where you are starting a Screen, and while being in App you can start another Screen, but this is almost like starting a new instance of application - memory and process allocation wise.

And, by using Virtual Screen, you always be in the same and the one Screen context.

and, I am familiar with Servlet Lifecycle, Process and Threads, etc.

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).

Maybe this explanation will help you a bit.

1 Like

(added to reorganized Screen Switching section of FAQ)

Thanks, this was very informative.

1 Like