Android Tutorial StateManager - Helps managing Android applications settings and state

Status
Not open for further replies.

roarnold

Active Member
Licensed User
Longtime User
Erel,

I like it, works well. Question. Each time the app is run it will process the State Manager app, correct?

Thanks,
R
 

luthepa1

Member
Licensed User
Longtime User
Ok I got something weird.... I have added the StateManager code module to project and all is working. If i enter text into a edittext view and rotate screen (so activity destroyed and recreated) the edittext view is repopulated witht eh text I had entered before rotating device. So that is good. All is working. But when I check a checkbox view and rotate screen/device the check status of that checkbox view is not restored! Not sure why?

I did make a edit to the innerSaveState and innerRestoreState to include the enabled status of button views. And when rotating my device the enabled status of the button is appropriately restored. So that works too!

I added a toast message tot he checkbox CheckChanged event and it shows true for checked and false for unchecked. The only other code that interacts with these checkbox view at the moment is positioning them on the screen with the Left statement. Nothing else.

Anybody have ideas why my checkbox view states are not restored? Code below

B4X:
Sub innerSaveState(v As View, list1 As List)
   Dim data() As Object
   If v Is Button Then      'DrP - Added button enabled status - 11JUL12
      Dim btn As Button
      btn = v
      data = Array As Object(btn.Enabled)
   Else If v Is EditText Then



Sub innerRestoreState(v As View, list1 As List)
   Dim data() As Object
   If v Is Button Then
      Dim btn As Button
      btn = v
      data = getNextItem(list1)
      btn.Enabled = data(0)
   Else If v Is EditText Then

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("CreateWorkoutMain.bal")
   scvCreateWorkout.Panel.LoadLayout("CreateWorkout.bal")
   
   InitCreateWorkoutLayout
   
   StateManager.RestoreState(Activity, "CreateWorkout", 60)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then
        StateManager.ResetState("CreateWorkout")
    Else
        StateManager.saveState(Activity, "CreateWorkout")
    End If
End Sub
 

luthepa1

Member
Licensed User
Longtime User
Yes. CheckBox is a special type of button. In your code you should first check for CheckBox and only then for Button.

Thanks Erel! That worked! Although I must admit I dont understand why it makes a difference? I mean each view has its state saved to a object list. I guess its something to do with what you ay about the checkbox view being a "special type of button".

Dont suppose you can fill me in or point me to a link that describes why? My curious mind wont give up.
 

BarrySumpter

Active Member
Licensed User
Longtime User
Just finished a layout for user properties and settings.
Like UserID and Password and RefreshRate, etc.

Then was wondering how to save the data.

Using StateManager I can't believe I need only two statements!

(unless I'm missing somthing)


B4X:
Sub Activity_Create(FirstTime As Boolean)
....
    'Load the previous state
    If StateManager.RestoreState(Activity, "Main", 60) = False Then
        'set the default values
    End If

End Sub

Sub Activity_Pause (UserClosed As Boolean)

        StateManager.SaveState(Activity, "Main")

End Sub

Freakin' Brilliant!
:sign0098:

Can't believe how quicky my design, testing, and apps are progressing.
 
Last edited:

barx

Well-Known Member
Licensed User
Longtime User
Looking through this code module, it doesn't seem to save any state for WebView, is this correct. If so, is there anyway to save WebView state?

I know I could save the current URL on Activity_Pause and ReLoad it on Activity_Resume but is there any way to save any text that has been entered into a text field on a site? i.e. the user decides to rotate device part way through replying to a forum post on a site. I doubt there will be a way but just thought I'd ask.

Thanks.
 

fajar

New Member
Licensed User
Longtime User
Reflector

can't run StateManagerExample sample
why reflector marked-on red?
 

enrico

Active Member
Licensed User
Longtime User
Prevent orientation change

I'm struggling in using State Manager properly for my project and I'm asking if there is a way to block the screen orientation change only in some activities.
I don't care if it's vertical or horizontal, but I would not want that it could be changed (only in this activity).
 

enrico

Active Member
Licensed User
Longtime User
I was thinking Phone.SetScreenOrientation can't do the job.
Can you please post a code example ?
 

enrico

Active Member
Licensed User
Longtime User
Ok, it works. I did not realize that it also blocks from rotating. Thanks
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…