简体   繁体   English

React Native 检测用户何时尝试退出应用程序?

[英]React Native detect when user is trying to quit the app?

I want to update my redux state based on the component unmount but in case a user terminates the app how to detect that and update my redux state based on the app termination as the componentWillUnmount will not be called in case of quitting the app. I want to update my redux state based on the component unmount but in case a user terminates the app how to detect that and update my redux state based on the app termination as the componentWillUnmount will not be called in case of quitting the app. Is there a way to detect app termination(not suspended) in react native?有没有办法在本机反应中检测应用程序终止(未暂停)?

I Guess Your Confusion Should Remove By Understand Following Approche:我猜你的困惑应该通过理解以下方法来消除:

 import React from "react"; export default class Clock extends React.Component { constructor(props) { console.log("Clock", "constructor"); super(props); this.state = { date: new Date() }; } tick() { this.setState({ date: new Date() }); } // These methods are called "lifecycle hooks". componentDidMount() { console.log("Clock", "componentDidMount"); this.timerID = setInterval(() => { this.tick(); }, 1000); } // These methods are called "lifecycle hooks". componentWillUnmount() { console.log("Clock", "componentWillUnmount"); clearInterval(this.timerID); } render() { return ( <div>It is {this.state.date.toLocaleTimeString()}.</div> ); } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在 Android 上的 React Native 应用程序中尝试对用户进行身份验证时收到来自服务器的 401 错误 - I receive a 401 error from the server when trying to authenticate a user in my React Native app on Android 如何检测用户何时截屏? (React Native, IOS 和 Android) - How to detect when a user screenshots? (React Native, IOS and Android) 如何在本机反应的杀死应用程序中检测应用程序? - How to detect an application in the kill app on react native? React 本机应用程序检测后台应用程序活动 - React native app detect background apps activity 尝试在 react-native 应用程序中呈现文档 - Trying to render document in react-native app 当应用程序被用户破坏时如何从React Native传递数据到Native模块 - How to pass data to Native module from React Native when the app is getting destroyed by the user 当用户从 web 应用程序进行任何更改时,我如何通知本机应用程序进行更改 - How can i notify react native app for the changes, when any changes is made by user from web app 尝试使用 expo CLI 发布 React Native 应用程序时连接 ECONNREFUSED 127.0.0.1:80 - connect ECONNREFUSED 127.0.0.1:80 when trying to publish react native app with expo CLI 如何在 Electron App Quit 上关闭 React App - How to Close React App on Electron App Quit 在React Native App中将语言更改为用户偏好 - Change Language as a user preferance in React Native App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM