I have a chat window. If a user leave chat i want mark it leaved. But chat windows codes working behind still, i cant stop it. So if a user leave from chat page not working code.
You can define a global variable IscurrentPage2 for page2 in code or service module. you can set the value is true when page2 is create or resume event, false is in pause event.
You can use the code to judge if page2 is current page
B4X:
if yourmodule.IscurrentPage2 then
connect database
else
disconnect
endif