ScrollView contents lost on rotation

William Hunter

Active Member
Licensed User
Longtime User
I have a rotation problem. The screen (panel) contents consist of two labels, three buttons and a ScrollView. On rotation, while all the other elements are restored, the contents of the ScrollView are lost. The ScrollView contains a number of CheckBoxes, each having associated checktext and labeltext, very similar to the posted CheckBox example. What would I have to code into RESUME and PAUSE in order the have the contents of the ScrollView restored? The ScrollView contents are dynamic, in that they are created from arrays containing header information previously downloaded from a mail server. This would change with each call to the server.

I have searched the forum and also read Chapters 9 and 15.1 in the Beginners Guide. I know that I have to SAVE in Sub Activity_Pause, and LOAD in Sub Activity_Resume. What I don’t know is what the code would look like in order to accomplish this.

With respect to StateManager, the code in Sub Activity_Pause seems to be a constant, while the code in Sub Activity_Resume is set by the user. If StateManager is to be used, what code should be entered into Sub Activity_Resume?

The Beginners Guide certainly covers the theory, but I need to see a code example before any of this will be clear to me. Help in this regard would be greatly appreciated.
:sign0104:
 
Last edited:

William Hunter

Active Member
Licensed User
Longtime User
:sign0142:
And, this will help me how? I’m sure you meant to be helpful, but you can roll manure in powdered sugar, and you still won’t have a jelly donut.

I thank you for your interest, but I'm done with searching for a code example relevant to my needs. There isn't one on this forum, and it would be most helpful if someone would pass a little expert knowledge my way.

Best Regards
 
Upvote 0

William Hunter

Active Member
Licensed User
Longtime User
It is hard to give you a concrete example without seeing your code.
Hello Erel – Thank you for the reply. I have spent a lot of time searching the forum, and reading the Beginners Guide as well as the Wiki – Tricks Of The Trade.

I have attached my code to this post and would appreciate a critique of the direction I have taken in its creation. I have two problems:

1. The ScrollView doesn’t scroll properly.

2. The ScrollView contents are lost on rotate.

Also, I have a ToastMessage at the beginning of Sub CreateScrollView for testing purposes. That ToastMesage repeats in unison with each cycle of the For i = 1 To messageCount loop. I should only see that message once. This one’s a mystery.

I have a sense that these problems exist because the ScrollView was created outside of Sub Activity_Create. If this is an absolute requirement, then I will have to rethink my approach, and start this project over again. Before I do this I would like to know whether there is a simple solution to these problems or not. If not, and starting over is a must, I would like to know what errors in structure I have made that should be avoided in the future.

I look forward to your reply. :BangHead:
 

Attachments

  • MailPurge.zip
    11.4 KB · Views: 158
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I have a sense that these problems exist because the ScrollView was created outside of Sub Activity_Create
There is no problem with creating views wherever you want.

The problem is that you declared all the messages related variables as Global variables instead of Process_Global variables. Therefore these variables are recreated together with the activity. As a general rule all non-UI variables should be declared as process global variables.
 
Upvote 0

William Hunter

Active Member
Licensed User
Longtime User
There is no problem with creating views wherever you want.

The problem is that you declared all the messages related variables as Global variables instead of Process_Global variables. Therefore these variables are recreated together with the activity. As a general rule all non-UI variables should be declared as process global variables.
Thank you Erel – I now have a better understanding of rotate, and Global declarations. However, I still have a problem in re-creating the ScrollView contents. On rotate, while all the CheckBoxes are re-created, only the CheckText and LabelText of the last item in the array are re-created. This does not occur initially, only on rotate.

In Sub CreateScrollView I have a glitch in the For i = 1 To messageCount loop that I can’t account for. You will notice that I have two ToastMessages in this Sub. One is in the loop, the other at the end of the Sub. The ToastMessage in the loop indicates that the loop persists continually beyond the messageCount. It restarts over and over again, and will not stop without intervention. The ToastMessage at the end of the Sub shows as being included in the loop. Both of these conditions are not normal. In my view, my code is correct. Could this be a glitch in B4A ,or have I made an error in my code that creates this condition?

I have uploaded my revised code and await your reply.
 

Attachments

  • MailPurge.zip
    11.4 KB · Views: 166
Last edited:
Upvote 0

William Hunter

Active Member
Licensed User
Longtime User
I think that you are missing the fact that the mail download action is asynchronous. This means that pop_Download2Completed is called many times. One time for each message. You are recreating the ScrollView every time.
Thank you Erel – As per usual, you are correct again. I had thought that with building in modular form I would have separation between Sub pop_Download2Completed and Sub CreateScrollView. But, as I now know, this is not so. “Coises, foiled again.”

I have learned a lot on the forum, and more specifically from you. Your timely responses and openness in sharing your knowledge are greatly appreciated.

I think that this project has run its course, and will remain uncompleted. For the moment, I can’t think of a way around the problem. If anyone following this thread has any thoughts as to how this issue might be resolved, please feel free to comment.

Regards :sign0188:
 
Upvote 0
Top