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