ReactNative 退出到后台一定时间之后,跳转到登录界面
2017-08-12 20:40
483 查看
****实现长时间不操作应用,可以自定义多长时间,直接跳转到登录界面,登录之后才能再进行操作**** let pTimes; let BACK_TO_LOGIN_TIME = 120; constructor(props) { super(props); this.state={ currentAppState:AppState.currentState, } } componentDidMount() { AppState.addEventListener('change', this.handleAppStateChange); pTimes =-1; } componentWillUnmount() { AppState.removeEventListener('change', this.handleAppStateChange); } handleAppStateChange = (nextAppState) => { if (this.state.currentAppState.match(/inactive|background/) && nextAppState === 'active') { let tempTime = getCurrentTime(); let waste = tempTime -pTimes; console.log('----'+preTimes+'----waste:' + waste) console.log('BACK_TO_LOGIN_TIME====='+BACK_TO_LOGIN_TIME) if (waste > BACK_TO_LOGIN_TIME) { InteractionManager.runAfterInteractions(()=>{ this.props.navigator.resetTo({ component:Login, name:'Login', }) }) toastShort('长时间未操作,需要重新登录') console.log('AppState:'+'It's too late,login again') }else{ console.log('AppState:'+'回来的很及时') } console.log('AppState:'+'现在在前台') }else{ //前台切换至后台 console.log('AppState:'+'现在在后台') preTimes = getCurrentTime(); } this.setState({ currentAppState:nextAppState}); console.log('pTimes:'+pTimes); } //返回从1970年1月1日至今的毫秒数 export function getCurrentTime(){ let date = new Date(); return date.getTime(); }
相关文章推荐
- 项目里的jsp页面一定时间(比如5分钟)未操作后,跳转至登录页
- Android关于界面一定时间无操作自动跳转到指定界面的实现
- 一定时间之后,页面自动跳转
- JS 退出系统并跳转到登录界面的实现代码
- 点击退出,并未直接跳转到登陆界面,登录界面还停留在框架集界面
- Android关于界面一定时间无操作自动跳转到指定界面的实现
- 如何延长zencart1.5后台的登录时间而不退出
- JS 退出系统并跳转到登录界面的实现代码
- JS 退出系统并跳转到登录界面的实现代码
- 如何延长zencart1.5后台的登录时间而不退出
- JS 退出系统并跳转到登录界面的实现代码
- 使用<frameset>标签生成界面之后 点击退出 页面整体跳转
- 在Ubuntu登陆界面输入密码之后,黑屏一闪后,又跳转到登录界面
- ecmall常见问题解决方案 解决ecmall前台后台登录成功后又跳转到登录界面,怎么解决。
- 退出系统并跳转到登录界面 JS代码
- 登录页面在输入了正确的用户名和密码后仍跳转到登录页面而不是期望的系统首页面,debug的时候发现,登录页面调用的action类方法被调用了两次,后台无法获取前台页面传过来的参数。
- 第二百二十九节,jQuery EasyUI,后台管理界面---后台登录
- 在一定时间内连续双击返回键退出应用
- Android7.0后台服务器更新之后使用Intent跳转至APK安装页
- 【转】asp.net中如何退出整个框架(frameset ),回到登录界面?