Android Question B4XPage_Appear not getting called

App Dude

Active Member
Licensed User
Longtime User
According to this post, B4XPage_Appear gets called whenever the page becomes visible. And this was working fine for weeks during development, but somehow does not anymore.

In file B4XMainPage, Sub B4XPage_Created, I have:
B4X:
...
page2.Initialize
B4XPages.AddPageAndCreate("page 2", page2)
page3.Initialize
B4XPages.AddPageAndCreate("page 3", page3)
...

Then to jump from one page to another, I just do:
B4X:
B4XPages.ShowPage("page 2")
when necessary.

This recently became intermittent (works some times but not at others)... it will always show the correct screen, but the B4XPage_Appear sub of the new page is not always being called.
This is also happening if I go to the home page, then reselect the app from the recent apps list... it should call B4XPage_Appear, correct?
I tried changing AddPageAndCreate to AddPage, but same thing.
Android 10.

What am I not understanding here?
PS: I can't post all the code, but let me know what important sections I should show.
 

Alexander Stolte

Expert
Licensed User
Longtime User
I don't know the solution to the problem, but I have a tip for you, you can abbreviate the following:
page2.Initialize B4XPages.AddPageAndCreate("page 2", page2)
B4X:
B4XPages.AddPageAndCreate("page 2", page2.Initialize)
 
Upvote 0

App Dude

Active Member
Licensed User
Longtime User
I found something interesting... I recently added notifications to the app so was testing around that, and found some strange behaviour. I've whittled it down to this...

For a test, I'm creating a notification on the first screen (MainPage).
If I click on a button to go to the second screen, B4XPage_Appear gets called properly.
However, if I click on the notification, then after that click on the button to go to the second screen, B4XPage_Appear does not get called.

I'm baffled.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try to reproduce it in a small program and upload it. You can start with the three pages example.
 
Upvote 0

App Dude

Active Member
Licensed User
Longtime User
More testing last night... it seems like it's related to the GPS service, which requires a notification in Service.StartForeground()
I've got it down to this minimal example app. You can click back and forth between pages and all works well. However, once you pull down the notifications and click on the GPS receiver notification, B4XPage_Appear no longer gets invoked.
 

Attachments

  • B4XPages_Notif_Issue_01.zip
    481 KB · Views: 182
Upvote 0

App Dude

Active Member
Licensed User
Longtime User
Oh! Honestly, I don't know. I've been building this app piece by piece for 2 months and I started from some previous example code I had. I don't remember where it started.
I'm trying this now and yes it does seem to work.
Thank you! Really appreciate the help on this.
 
Upvote 0
Top