AHViewPager - Set Starting Page?

yttrium

Active Member
Licensed User
Longtime User
When using AHViewPager and three pages, the default starting page is 0, and no matter what I attempt to do I can't make users see page 1 when the app initializes. Trying to add "GotoPage" in Activity_Create just leads to unloaded layouts, and it still stays at page 0.

Trying to put the page change onto a background thread leads to a NullPointerException, which can be safely disregarded, and then the following:
B4X:
An error has occurred in sub: main_activity_resume (java line: 358)
java.lang.IllegalStateException:
The specified child already has a parent. You must call removeView() on the child's parent first.
Continue?

Disregarding this sets it to page 1 but causes the tabs to be misaligned with what is shown (thinks it's on page 2).

Trying to navigate away force closes the app.

Any ideas?
 

yttrium

Active Member
Licensed User
Longtime User
I use it in activity resume, and it works fine for me.

I didn't know Activity_Resume fired when an app launched - that explains my issue. I have the following at the beginning of my Activity_Resume:
B4X:
Sub Activity_Resume
   pager.GotoPage(CurrentPage, False)
This is meant to work with an action in Activity_Pause, where the current page is stored before the app is closed - that way the app re-opens to the same page when resumed. However, the default value for this variable is 0, not 1, and so it overrides any GotoPage method in Activity_Create.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
I didn't know Activity_Resume fired when an app launched - that explains my issue. I have the following at the beginning of my Activity_Resume:
B4X:
Sub Activity_Resume
   pager.GotoPage(CurrentPage, False)
This is meant to work with an action in Activity_Pause, where the current page is stored before the app is closed - that way the app re-opens to the same page when resumed. However, the default value for this variable is 0, not 1, and so it overrides any GotoPage method in Activity_Create.

Yes, Activity_Resume always runs when the app starts. First create runs, and then resume.
I think you can safely set the value of CurrentPage = 0, inside activity_create and that should work fine. (You can set a different default after GotoPage in activity resume as well probably).
 
Upvote 0

yttrium

Active Member
Licensed User
Longtime User
Yes, Activity_Resume always runs when the app starts. First create runs, and then resume.
I think you can safely set the value of CurrentPage = 0, inside activity_create and that should work fine. (You can set a different default after GotoPage in activity resume as well probably).

Setting CurrentPage to 1 in Process_Globals (so that it may be accessed after the activity, but not the process, is destroyed) fixes this perfectly. I don't touch it in Activity_Create, and instead go to CurrentPage at the beginning of Activity_Resume - reusing the same code for two different operations.

Also, I was apparently defining CurrentPage both in Process_Globals (as 0) and in Globals (with no value), so that probably had something to do with it too.

Working now, thanks!
 
Upvote 0
Top