This behavior is expected in Power Apps mobile.
When a user swipes away (force closes) the app, Power Apps does not trigger any event like:
OnHidden
OnTimerEnd
OnSelect
OnPause
Exit()
The app is simply terminated by the OS.
So you cannot reliably invalidate a session on swipe close from inside Power Apps.
Correct Solution (Production-Ready Approach)
1 – Store Last Activity Time - When user logs in (App.OnStart):
Set(varSessionID, Host.SessionID);
Patch(
SessionTable,
Defaults(SessionTable),
{
SessionID: varSessionID,
UserEmail: User().Email,
SessionStart: Now(),
LastActivity: Now(),
Status: "Active"
}
)
2 – Update LastActivity on Every Action - On important screens or button clicks
Patch(
SessionTable,
LookUp(SessionTable, SessionID = varSessionID),
{
LastActivity: Now()
}
)
This keeps the session alive while user is active.
3 -Handle Expiry From SQL (NOT Power Apps) - Create logic in SQL
UPDATE SessionTable
SET Status = 'Expired',
SessionEnd = GETDATE()
WHERE Status = 'Active'
AND DATEDIFF(MINUTE, LastActivity, GETDATE()) > 10
You can run this via:
- SQL Job
- Stored Procedure
- Power Automate scheduled flow
This works even if user force closes app
This works even if mobile kills process
No dependency on Exit()
4 – Validate Session When App Opens - In App.OnStart
Set(
varSessionRecord,
LookUp(SessionTable, SessionID = Host.SessionID)
);
If(
DateDiff(varSessionRecord.LastActivity, Now(), Minutes) > 10,
Patch(
SessionTable,
varSessionRecord,
{
Status: "Expired",
SessionEnd: Now()
}
)
);
If expired → force new session.
24/7 Power Platform Support - Click Here
Best regards,
Pankaj Jangid (OyePanky)
Power Platform Developer
YouTube: https://www.youtube.com/@oyepanky
Website: https://www.dialforit.com