Home > Blockchain >  Run action before Ionic Vue closes or app runs in background
Run action before Ionic Vue closes or app runs in background

Time:09-17

How can i detect in Ionic Vue if the app closes or if the app is send to the background?

this.platformor platform isn't available or does not work?!

CodePudding user response:

You can subscribe to the appStateChange event, like described here: https://capacitorjs.com/docs/apis/app

Example:

import { App } from '@capacitor/app'

export default {
  created () {
    App.addListener('appStateChange', state => {
      if (!state.isActive) { // if isActive is true, App got sent to foreground, if it is false, it got sent to the background
        ...
      }
    })
  }
}
  • Related