0

I have built an android twa(trusted web activity) app from angular 8 PWA(progressive web app) using bubblewrap. The app has Google Signin button, to login into the app, and view the other screens in the app.

When the app is minimized, i would like to logout the user automatically. This means, when the user brings the app again to foreground, user should see the login screen.

Are there any callback methods available to TWA, for android app lifecycle?

jkr
  • 630
  • 1
  • 11
  • 24

1 Answers1

0

In order to track if a web page is visible to the user, you can use the Page Visibility API on the web app. You could, for instance, listen for the visibilitychange event and sign out the user when the page is no longer visible.

document.addEventListener('visibilitychange', function() {
  if (document.visibilityState !== 'visible') {
    signOut()
  } 
});

The advantage of this approach instead of hooking up to the Android lifecycle is that it will work on the standalone browser, including when switching tabs, and installed PWAs.

andreban
  • 4,621
  • 1
  • 20
  • 49
  • There are multiple pages(history, settings, home, etc) within the app, including side navigation/drawer menu. Where should i keep this code? – jkr Feb 04 '21 at 10:39
  • You'll likely need in a JS that is used by all pages. – andreban Feb 04 '21 at 11:30