React native 应用程序处于后台后,react native中的setInterval会发生什么变化?

React native 应用程序处于后台后,react native中的setInterval会发生什么变化?,react-native,timer,React Native,Timer,我设置了一个计时器,每5分钟刷新一次屏幕 componentWillMount() { this.handle = setInterval(() => this.props.refreshData(), 300000); this.props.refreshData(); } 在componentWillUnmount中,我清除了句柄 componentWillUnmount() { clearInterval(this.handle); } 当应用程序移动到后台时,计时器

我设置了一个计时器,每5分钟刷新一次屏幕

componentWillMount() {
  this.handle = setInterval(() => this.props.refreshData(), 300000);
  this.props.refreshData();
}
在componentWillUnmount中,我清除了句柄

componentWillUnmount() {
  clearInterval(this.handle);
}

当应用程序移动到后台时,计时器会发生什么变化?它会自动暂停吗?或者即使应用程序在后台,它还会继续运行吗?谢谢。

Android将不允许您设置超过2分钟的间隔或超时。你应该在Android上得到一个警告,我相信在生产中,当状态更改为后台时,应用程序将“崩溃”。

如我所见,它将使用
react native ios
自动暂停,但在
Android
中不确定。如果它没有在android中运行,你可以在应用程序从空闲模式运行时使用AppState重新设置。谢谢。减少了android的超时时间。但它没有崩溃。@vijayst我不认为这是完全崩溃,只要重新启动你的应用程序,如果我没记错的话。您在发布版本中尝试了5分钟的间隔?我在尝试之前缩短了超时时间。如果以1分钟的间隔重新启动,我将检查日志。