Question about StateManager

marbellapc

Member
Licensed User
Longtime User
Solved: Question about StateManager

Hello again, here I am again with a question.
I used the example of Kimmowich "Activity Translation" with the "StateManager" of Erel.

The story is that it works great, but I have a problem, when I leave the application and any other open, close it and get back into my application, I noticed that the settings do not save and StateManager makes my defaults, which I had not saved.

I've seen Erel put a solution I think it was for that, but I do not working.
B4X:
Sub Activity_Pause (UserClosed As Boolean)        
StateManager.SaveState(Activity, "Main")       
StateManager.SaveSettings
End Sub
What I like is if I answer there a way to permanently save the configuration as StateManager or is you have to use another system, because I have not been able to find anything concrete.

Greetings and excuse my English.
 
Last edited:

Kimmowich

Member
Licensed User
Longtime User
Hey

I assume you mean the setting of wich language-file to use..

I did look at your code and noticed something.

B4X:
Sub CheckBox_lang_CheckedChange(Checked As Boolean)
    If Checked = True Then
      lang = 0
   Else
      lang = 1
   End If
   Translate.ThisActivity(Activity)
End Sub

You need to change it to:
B4X:
Sub CheckBox_lang_CheckedChange(Checked As Boolean)
    If Checked = True Then
      lang = 0
   Else
      lang = 1
   End If
   Translate.File_init(LFile(Lang))
   Translate.ThisActivity(Activity)
End Sub

sincerly
 
Upvote 0

marbellapc

Member
Licensed User
Longtime User
Thanks Kimmowich, but yours works well, the problem I have it as I have said I StateManager CheckBox and temporarily saves the EditText, but once I leave, I open another application and any other get back into the application I'm creating, this does not load the values ​​that had previously gotten into the EditText and CheckBox.

And what if StateManager is not only stores temporarily or permanently can save changes in those EditText and others.

On the other hand change the CheckBox on Button.
B4X:
Sub Button_save_disp_Click
Dim UserClosed As Boolean
    If UserClosed Then
        StateManager.ResetState("opciones_disp")
    Else
        StateManager.SaveState(Activity, "opciones_disp")
    End If
    StateManager.SaveSettings
   ToastMessageShow("Configuracion guardada", True)   
' ----------------------------------------------------------- Al guardar indicamos tambien que se cambie el idioma.      
   If es Then
      Translate.File_init(LFile(lang))
   Else
      Translate.File_init(LFile(lang))
   End If
   es = es = False
   Translate.ThisActivity(Activity)   
End Sub
And it's perfect, but as the fault I have it in StateManager

Regards
 
Last edited:
Upvote 0

marbellapc

Member
Licensed User
Longtime User
Hi, I'm stupid, I have not noticed yet that more and pulsating close application.
was doing this:
B4X:
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then
StateManager.ResetState("Main")
Else
StateManager.SaveState(Activity, "Main")
End If
StateManager.SaveSettings
   GPS1.Stop
End Sub
When should be:
B4X:
Sub Activity_Pause
   GPS1.Stop
End Sub
I feel the inconvenience of my stupidity in not looking at the code.
Regards
 
Upvote 0
Top