admin管理员组

文章数量:1289928

Capacitor provides an App plugin that allows to get a call back when the application goes background or foreground. But how to get the application isActive value (a.k.a. foreground/background state) at any moment? The problem is that I don't know the application state until I subscribe to the appStateChange event AND the app goes background or foreground.

Capacitor provides an App plugin that allows to get a call back when the application goes background or foreground. But how to get the application isActive value (a.k.a. foreground/background state) at any moment? The problem is that I don't know the application state until I subscribe to the appStateChange event AND the app goes background or foreground.

Share Improve this question asked Feb 27, 2020 at 14:04 FinesseFinesse 10.8k7 gold badges71 silver badges93 bronze badges 1
  • 1 I've reported a feature request to Capacitor developers: github./ionic-team/capacitor/issues/2500 – Finesse Commented Feb 28, 2020 at 1:25
Add a ment  | 

2 Answers 2

Reset to default 8

A method to get the current state was added recently:

import {Plugins} from '@capacitor/core';

const {App} = Plugins;

let {isActive} = await App.getState();

document.hasFocus()

This will return a boolean. If the tab the web-app is in has the focus then it will return true else it will return false

source: https://developer.mozilla/en-US/docs/Web/API/Document/hasFocus

本文标签: javascriptHow to check if the application is foreground or background nowStack Overflow