Android Question Using StateManager with custom libraries like the AHViewPager

base64

Member
Licensed User
Longtime User
Hello,

StateManager does not seem to save & restore the states of views inside AHViewPager and the AHViewPager itself. How do I modify StateManager so that it does?

Tried making StateManager access AHPageContainer's panel, but AHPageContainer isn't a part of the Activity. Meanwhile, the AHViewPager, which is added to the Activity, does not seem to provide a way to access its AHPageContainer.

Thank you.
 

corwin42

Expert
Licensed User
Longtime User
You can get the AHPageContainer object from a Viewpager with this little helper sub (with the use of JavaObject):

B4X:
Sub GetPageContainer (vpg As AHViewPager) As AHPageContainer
    Dim jo As JavaObject
   
    jo = vpg
    Return jo.RunMethod("getAdapter", Null)
End Sub

If you get this working I would be very interested in your changes/additions to the Statemanager code.
 
Upvote 0

nhz

Member
Licensed User
Longtime User
You can get the AHPageContainer object from a Viewpager with this little helper sub (with the use of JavaObject):

Code:
Sub GetPageContainer (vpg AsAHViewPager) AsAHPageContainerDim jo AsJavaObject

jo = vpgReturn jo.RunMethod("getAdapter", Null)End Sub
If you get this working I would be very interested in your changes/additions to the Statemanager code.
I spent all day long trying to get this working. May I know where to place the helper sub?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
May I know where to place
Code Snippets forum. But please note the sticky thread to know how the post must be designed (Keywords)...
 
Upvote 0

base64

Member
Licensed User
Longtime User
You can get the AHPageContainer object from a Viewpager with this little helper sub (with the use of JavaObject):

B4X:
Sub GetPageContainer (vpg As AHViewPager) As AHPageContainer
    Dim jo As JavaObject
 
    jo = vpg
    Return jo.RunMethod("getAdapter", Null)
End Sub

If you get this working I would be very interested in your changes/additions to the Statemanager code.


Thanks, that helps.

Now, is there a way to force all page creations in Activity_Create instead of waiting until the page is needed?

Because StateManager can't restore the state if not all pages have been created (Object should be first initialized exception).

Also, is there a way to not have pages deleted and recreated when using AHViewPager so that states of all pages can be accessed at once?
 
Last edited:
Upvote 0

corwin42

Expert
Licensed User
Longtime User
It is possible to modify the buffering of the ViewPager so it won't only create one page left and right of the current one but it can create more.

For setting this offset to a higher value see this post.

In the android documentation is a hint that this value should be kept as low as possible. So I would not recommend to set it very high.
So saving the state may be possible for 3-4 pages but for more they should be regenerated (that's what I do in my apps always)
 
Upvote 0
Top