Android Question StateManager Not Working in my Layout

junaidahmed

Well-Known Member
Licensed User
Longtime User
I have four EditText in my Layout.I have updated the value in four EditText.When I rotate Screen,the data of all four EditText has reset.Please check attached layout File and advise the same...

I have tried StateManager also but I have not solved this problem....

B4X:
Sub Activity_Pause (UserClosed As Boolean)
        
    If UserClosed Then
        StateManager.ResetState("Main")
    Else
        StateManager.SaveState(Activity, "Main")
    End If
    StateManager.SaveSettings

End Sub
 

Attachments

  • dairy_layout.bal
    7.5 KB · Views: 282

DonManfred

Expert
Licensed User
Longtime User
if you leave your app using the Backkey the settings are resetted (UserClosed is true)
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
Please check the below log

Logger connected to: LENOVO Lenovo A2010-a
--------- beginning of main
--------- beginning of system
** Activity (main) Create, isFirst = true **
autoversion: 582.0
compilation time: 03/12/2018 11:51:23
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
WakeLock already held.
autoversion: 582.0
compilation time: 03/12/2018 11:51:23
** Activity (main) Resume **
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
As per your request,Here I am attaching small project which contain only one layout....
 

Attachments

  • StateManager.zip
    463.9 KB · Views: 294
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. See the warnings. You cannot show Msgbox from Activity_Pause.
2. Don't use Msgbox at all. Use Log instead. See the debugging tutorial.
3. Your layout is wrong. There should never be two views anchored to BOTH on the same horizontal or vertical line. See the visual designer tutorial: https://www.b4x.com/etp.html
4. You are not using StateManager correctly. See the tutorial: https://www.b4x.com/android/forum/t...applications-settings-and-state.9777/#content
You should restore the state in Activity_Create.
5. Please use File - Export as zip when you upload projects to the forum.
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
Thanks for above points....

As per your request, I have restore "State" in "Activity_Create" Event.....

It works fine as per my requirement, but why "Runtime view not saved" ??? ,
Actually I have used "GallaryView" in runtime but When I restore "State" ,the Gallaryview not updated.....
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Actually I have used "GallaryView" in runtime but When I restore "State" ,the Gallaryview not updated.....
Not all the elements are saved. Only elements which the user interacts with (like EditText text, Spinner chosen item, SeekBar value...).
!!!
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
Actually I have Added 3 Thumbnail Image in Gallaryview....

So, It is not possible to use "SaveState" for 3 Image in GallaryView ???
 
Upvote 0
Top