React Native:您的应用关闭时是否有回调函数? [英] React Native: Is there a callback function for when your app is closed?

查看:91
本文介绍了React Native:您的应用关闭时是否有回调函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个setInterval,即使你关闭(不退出)应用程序也会继续运行。我想在我的应用程序关闭或设备进入休眠状态时调用一个函数,以便清除setInterval。

I have a setInterval that keeps running even when you close (not quit) the app. I would like to call a function when my app is closed or the device is put to sleep so that it clears the setInterval.

推荐答案

itinance很接近。答案实际上是使用

itinance was close. The answer is actually to use

AppState.addEventListener('change', state => {
  if (state === 'active') {
    // do this
  } else if (state === 'background') {
    // do that
  } else if (state === 'inactive') {
    // do that other thing
  }
});

这篇关于React Native:您的应用关闭时是否有回调函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆