Android MobileScreen instance

Hi to all
Could you please help me to understand if this is a bug or a feature?

I have a MobileScreen (Screen2) with a string property (test as string)
In Screen2 I have a method (Constructor(value as string)) that takes value and set it to test
In the Activated event of Screen2 I have code to show the test property

Label3.Text = test

Screen1, the default mobile screen, has a button that (should) create a new instance of Screen2

Var value As String
value = TextField1.Text
Var a As New Screen2(value)
a.Show

Screen2 has the same button

What it happens?

  1. You run the app and see Screen1 → ok
  2. You write a value (value 1) and push Button1, Screen2 appears and you can see the value (value 1) you set → ok
  3. You write a new value (value 2) in Screen2 and push Button1 (in Screen2) and a (new?) Screen2 with the new value (value 2) appears ->ok
  4. Repeat point 3 as much you like, it works → ok
  5. Click on Back Button, actual Screen2(n) disappears and previous Screen2(n-1) appears; surprise, test value is not as it was, but is the last set → not ok
  6. Repeat point 5 as much as Screen2 you set before, every Screen2 has the same test value → not ok

It seems to me that the test property is shared between every single instance of Screen2
Am I wrong?
Thanks

MobileScreen instance.xojo_xml_project.zip (3.9 KB)

I remember reading somewhere that MobileScreen on Android is a singleton.
If you open two Screen2 objects, they both share the same property values.

1 Like

Thanks Jeremie, this has sense
I searched on official documentation, some videos on youtube and google, but didn’t find anything about this (probably a lack in my search)

To solve my problem, I created an array (history_test() as string) where store test values
My idea was to add the new value at opening event, use last of array in code and remove last on closing event
The problem was that, in my tests, closing event of MobileScreen(n) was fired after activated event of MobileScreen(n-1) when pushed back button, so MobileScreen(n-1) had value of MobileScreen(n), not good
So I have to add the new value in history at construction, remove immediately it at activation, and re-add it when new MobileScreen is created. In this way it shows me the correct values
It’s not elegant code, maybe someone could use a more efficient way (please share it)

MobileScreen instance 2.xojo_xml_project.zip (4.0 KB)