How do you use same ClientSocket on different screens?

Hello,
I stuck at the following problem designing a new Android App.

On the first screen (Screen1) I open a ClientSocket to get date from a server. That works perfectly.
Now I would like to use a second screen (Screen2) to display different data from the same server.
Unfortunately that fails, because I do not know how the deal with the settings from Screen1.
I always get errors because I have no access to old settings.
Same thing if I switch back from Screen2 to Screen1. It seems the old settings are not valid anymore,
because I can not get new data. But it worked before switching from Screen1 to Screen2.
I'm using ClientSocket.ConnectionState on Screen1 , but I do not get the effect I expect.

Do I misunderstand anything ? Can anybody help, please?

Thank you.

Robert

,

Switching screens is akin to running another program.
That breaks connections and reinitializes variables.

Consider instead sticking to one screen, and stacking Vertical Arrangements, only one Visible at a time.

Oh, thank you for this information. I was not aware of it.
Am I right if if have to disconnect the client from server before I switch to the new screen and vise versa. A disadvantage would then be that all old data get lost , right ?

MultipleScreen.aia (849.0 KB)

It's much simpler to rearrange your app, as @ABG has already said. You can find attached an example on how to use H/V layouts to simulate "true" screens.

Thanks a lot for the MultipleScreen example. I'll try to change my app according to
the example.
Could be I stuck again because I'm doing the first steps with App Inventor. Then I'll
come back and ask.

All your help is very appreciated.

Feel free to ask :hugs: :hugs: :hugs:

Hello,
I think I understand how virtual screens work and I have already successfully managed to
rearrange my project. It currently consists of two virtual screens.
However, I trapped into a further problem displaying the serial data I get from server.

The violet marked area is a procedure outside of screen1 and 2 and the result is
always visible. That works as expected, I can see the data coming from the server.

The green marked area however specifies procedures just in screen1. This is not working.
I can't see the filtered data from stream.

Can anybody explain what is missing or wrong with the setup, please?

Thank you.

:question:

If the value in "data" is coming through, check your logic for extracting specific data from it.

This part doesn't make much sense, given your other blocks

image

Yes, data is coming through. The extraction logic is ok in case of just a single screen (no virtual screens!)
It seems data is not valid in a virtual screen.

As has been recommended, do everything on one screen, using virtual screens to view different layouts.

Because I like the multiscreen option, I maybe found another solution for my problem.

I store the incoming data stream in TinyDB any time data have arrived.
To display single values out of the stream or certain data in a chart on different screens, I readout TinyDB , process them. So far it seems to work.

Thanks for your ideas,anyway.

You will find that you have to switch screens to fetch new data, then switch back again in order to read it. Not very practical...

No, that is not what I'm doing.
The process which reads the data and store them in TinyDB is beyond of the screens.
The processes which are used within the different virtual screens read the data out
of the DB.

Dear @roty,
it's still not clear what you mean for "beyond the screens": is the receiving procedure laying in another screen (rather than in Screen1) ? Or is it laying in background by the use of Itoo extension ?
For a better understanding, could you please post your .aia fiile ?

Sure, I want to learn from experts!
As already mentioned, I'm a beginner with APP Inventor. Could be I'm programming nonsense code.

I can not post my code completely. However, I'll add an extraction of my code. What you see is
also works at my side and shows the method how I managed to support the two virtual screens
with date from a server.
It wound run anywhere else, because a certain serial data stream from a server is required.

Hopefully now it's more clear what I'm doing and hopefully the code is not that painful!

SP_MScreen(1).aia (219.5 KB)

Your aia only has one real screen. Confusion.

I'm confused.

I thought I have one real screen and two virtual screens according to the example by @ABG .

You said this earlier in the thread, after I suggested to just use one screen:

Have you now decided to just use one real screen (Screen1), with virtual screens (Vertical Arrangements) in that real screen ?

Are several virtual screens not multi-screens?