React Native 在 android 按下主页按钮时重新启动

React Native restarts on home button pressed on android

当我使用应用选择器并转到另一个应用并return进行挖掘时,效果很好。 这是我的 App 组件

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View
} from 'react-native';
import { observable, action } from 'mobx';
import { observer } from 'mobx-react'
import { SplashScreen } from './screeens/SplashScreen';
import { DashboardScreen } from './screeens/DashboardScreen';
import { AppNavigator, AppNavigatorNoAuth } from './routes';

@observer
export default class App extends React.Component {
  @observable isInitialized = false;
  @observable isFontInitialized = false;
  @observable isLoggedIn = false;

  @action
  initializeApp = async () => {
    setTimeout(() => {
      this.isInitialized = true;
    }, 3500)
  }

  componentDidMount = () => {
    this.initializeApp();
  };


  render() {
    if (!this.isInitialized) {
      return <SplashScreen />
    } else if (!this.isLoggedIn) {
      return <AppNavigatorNoAuth />
    } else {
      return <AppNavigator />
    }
  }
}

经过一些调查,在 react-native 回购 https://github.com/facebook/react-native/issues/7079 中找到了这个错误报告 我尝试了 "rreusser" 的解决方案,它奏效了。 我在 manifest.xml

的主要 activity 声明中添加了 android:launchMode="singleTask"