I am making two screens A and B. Let's say they are screenA & screenB.
In screenA, I use setScreen(screenB) to pass the screenA to screenB.
In screenB, I have two methods two pass the screenB back to screenA.
Method 1
I create an imageButton called "Back". When I press the imageButton, it will use setScreen(screenA) to pass the screenB back to screen A.
Method 2
I use the soft key Keys.BACK to pass the screenB back to screenA.
My question s are:
1) Is method1 the same as method2?
2) Is my concept below correct?
Method1 Stack: screenA-->screenB on top-->Another ScreenA on top.
Mehod2 Stack: A-->screenB on top, then screenB is remove (if Keys.BACK is pressed) and back to A only.
If my concept is correct, will Method1 use more memory than Method2?
I hope you can understand my question and sorry for any troublesome.
Thanks for reply.
I have the belief that setScreen() is not doing what you think is doing. setScreen() does not manipulate any stack. When you set the Screen the previous Screen is just removed and replaced from the new that you have added.
Let's say you do setScreen(ScreenA), then from ScreenA you do setScreen(ScreenB) -> ScreenA is removed and replaced by ScreenB. If you want to have a stack you can make your own. Usually I use a List and add each Screen on top and when back is pressed I pop it from List and I setScreen() the last Screen of the List.
On Keys.Back or Back button you would have the same logic.
And usually you would want to use this line in order to manipulate the back key with your logic.
Gdx.input.setCatchBackKey(true);