Android Tutorial StateManager - Helps managing Android applications settings and state

Status
Not open for further replies.

Claudio Oliveira

Active Member
Licensed User
Longtime User
Hey everybody,
I noticed that every time I used StateManager to save/restore CheckBox states, it did save/restore the CheckBox label instead, and not it's checked state as it was supposed to. And the same happened to ToggleButton and RadioButton.
I'm running Android 5.0.1 on a Samsung Galaxy S4.
After some logging, I found out that CheckBoxes trigger the "Label" section of the "if ... else" structure in StateManager code.
I was not quite sure about the reason for such unexpected behaviour, but I guessed it was because a CheckBox, Toggle and Radio Buttons are sort of "composite" views. They have the label and functional part (check box or toggle) together.
Maybe Erel could clarify this point...
Anyway, I positioned the CheckBox's, RadioButton's and ToggleButton's code sections BEFORE the Label's code section in the "if ... else" structure in both innerSaveState and innerRestoreState subs.
Everything's working fine now.

Regards,
Claudio Oliveira
Rio de Janeiro - Brasil
 

Yves Mazzon

Member
Licensed User
Longtime User
 

Yves Mazzon

Member
Licensed User
Longtime User
Dear Erel, I need a push start on StateManager. How can I apply it to my code. Where the bas module has to be placed? Do I have to modify the stageManager.bas for my application? Many thanks for your time. Hopefully soon I will stop asking stupid questions.
Yves
 

Claudio Oliveira

Active Member
Licensed User
Longtime User
@Yves Mazzon save the layout file after you open it and it will work.

StateManager doesn't do anything with labels. Maybe you have downloaded the wrong module.
Yeah. That's right.
I've donwloaded the correct module now. StateManager indeed has nothing to do with labels at all.
Now I've got to find out WHERE did I get this module from!!!
Thanks Erel
 

Yves Mazzon

Member
Licensed User
Longtime User
Thanks Erel but I must be missing something. I have added the module with the "Add Existing Module" and pointed to the satemanager.bas in the same folder where the .b4a is. Didn't modified my code but when I compile I get an error see attach. Did I get the right satemanager.bas see also attached? Really getting stuck with this.
Thank you
 

Attachments

  • Error.JPG
    65.9 KB · Views: 461
  • StateManager.bas
    6.9 KB · Views: 484

Yves Mazzon

Member
Licensed User
Longtime User
See the error message. You need to add a reference to the RandomAccessFile library.
Thank you Erel but I'm a beginner and need to get a bit more explanation. Sorry for my ignorance. How do I add a reference to the RandomAccessFile library?
Many thanks for your help.
Regards,
Yves
 

Nb1320

Member
Licensed User
Longtime User
Hello,
Is it possible to pull the information from the save file that the statemanager creates and make a list(s) out of it for another activity in the app?

Thanks!
 

Adilson Jacinto

Active Member
Licensed User
Longtime User


Hi Erel,

How do I add the StateManager? is that a library? it is because I cannot find it.
 

agb2008

Member
Licensed User
Longtime User
In my application I've tried to replace my custom state_save/state_restore functions with StateManager ones...
But I was unable to succeed - probably because of my application design - could you please advice if it's indeed the
case or if I am doing something wrong.

In my case I've use following code in Activity_Create module:

B4X:
    Activity.LoadLayout("Main")
   
    scvMain.Height=-1
    scvMain.Width=-1

    scvMain.Panel.LoadLayout("Panel1")
    scvMain.Panel.LoadLayout("Panel2")
    scvMain.Panel.LoadLayout("Panel3")
    scvMain.Panel.LoadLayout("Panel4")
    scvMain.Panel.LoadLayout("Panel5")
   
    scvMain.Panel.Height = pnlCalc1.Height

Where Main layout consist of just single ScrollView object. And Panel1 - Panel5 are panels created in Visual Designer.
(Main layout [scvMain] created in Visual Designer as well) Initially only Panel1 is in Visible state, other panels hidden.
When needed application control which panel became active and user could input/change some info on these panels.

Problem as I've observed it is that when I am using StateManager to save application state for example to avoid data
loss during screen rotation procedure only information from first Panel1 saved...

So my question is: could StateManager save information from multiple panels, some of which are in not Visible state or
it would only deal with main active object ?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…