【问题标题】:Angular WPA How to know if the application is in backgroundAngular WPA 如何知道应用程序是否在后台
【发布时间】:2019-08-13 20:39:47
【问题描述】:

我使用 SetTimeout 每 10 秒刷新一次来自 Web api 的数据。我在 onDestroy 中停止它(干净)。完美运行????

但是,由于我的应用是 WPA,我意识到,当我点击手机的 Home 按钮时,该应用仍在进行刷新调用。有什么方法(属性或事件)可以知道应用程序何时在后台运行,所以我可以停止我的计时器。

谢谢你的时间????

【问题讨论】:

    标签: angular rxjs wpa


    【解决方案1】:

    终于找到了一些东西:只需使用 HostListener 来观察窗口焦点/模糊事件,然后启用/禁用我的计时器。

    @HostListener('window:focus', ['$event'])
    onFocus(event: FocusEvent): void {
      this.nasTimer.start();
    }
    
    @HostListener('window:blur', ['$event'])
    onBlur(event: FocusEvent): void {
      this.nasTimer.stop();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-21
      • 1970-01-01
      • 2015-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-02
      相关资源
      最近更新 更多