首页 > 解决方案 > React-native Android:应用程序在恢复时卡在启动画面上

问题描述

恢复后我的应用卡在启动画面上:

这是我的依赖项:

"react-native": "^0.57.4",
"react-native-code-push": "^5.4.2",
"react-native-collapsible": "^1.1.0",
"react-native-datepicker": "^1.7.2",
"react-native-fast-image": "^5.1.0",
"react-native-geocoder": "git://github.com/pizzahutuk/react-native-geocoder",
"react-native-google-analytics-bridge": "^6.1.2",
"react-native-google-autocomplete": "^0.1.5",
"react-native-image-picker": "^0.27.1",
"react-native-iphone-x-helper": "^1.2.0",
"react-native-linear-gradient": "^2.4.2",
"react-native-maps": "git://github.com/react-community/react-native-maps.git#1844d46902629e2caa55527d5bff48a550d92525",
"react-native-picker-select": "^4.4.0",
"react-native-sensors": "^4.0.0",
"react-native-splash-screen": "^3.1.1",
"react-native-svg": "^8.0.8",
"react-native-video": "^3.2.1",
"react-navigation": "^2.16.0",
"react-navigation-redux-helpers": "^2.0.6",
"react-redux": "^5.0.7",
"react-router": "^4.3.1",
"redux": "^4.0.0"

这是问题期间来自 adb logcat 的日志:

11-13 15:45:30.710 2290 2290 W ResourceType: 获取资源号 0x9c020204 的名称时没有已知包 11-13 15:45:30.710 2290 2290 I HwLauncher: Launcher onclick begin com.huawei.android.launcher.BubbleTextView{d7d30af VFED..CL。...P..ID 528,1280-792,1570 #9c020204} 11-13 15:45:30.710 2290 2290 I HwLauncher:Launcher.Utilities startActivitySafely useLaunchAnimation = true 11-13 15:45:30.710 2290 2290 I HwLauncher: Launcher.Utilities startActivitySafely 为当前用户启动 startActivity() 11-13 15:45:30.714 2239 2239 I K3V3CpuGovernorPolicy: 设置场景 Hmp 策略: 300 , 150 11-13 15:45:30.717 2290 2290 I HwLauncher: Launcher.Utilities startActivitySafely end当前用户的 startActivity() 11-13 15:45:30.717 2290 2290 I HwLauncher:启动器此视图的父级不是 SearchGridView ,因此无需报告RecentApp。开发者WebMonitor [mNetWorkIsSuck=false mUIDIsSuck=] WebSpeed [WEBSENDSEGS=132 WEBRESENDSEGS=8 WEBRECVSEGS=89 WEBERRSEGS=0 WEBOUTRSTS=5 WEBESTABLISRST=0 WEBRTTDURATION=253 WEBRTTSEGS=38 WEBSRTT=860 WEBSNDDUPACKS=0 SENDSEGS=0 RESENDSEGS=0 RECVSEGS =0 OUTRSTS=0 ESTABLISRST=0 RTTDURATION=0 RTTSEGS=0 SNDDUPACKS=0 sinkTimes=0 recovage_times=0] 11-13 15:45:30.844 961 1084 I ActivityManager: 显示 air.com.unit9.frapp/.MainActivity: + 124 毫秒 11-13 15:45:30.898 12692 12738 我 ReactNativeJS:[CodePush] 检查更新。11-13 15:45:30.903 12692 12705 I art : 对象分配现在很忙,所以在增加堆之前。新堆大小为 45 MB 11-13 15:45:30.919 12692 12738 I ReactNativeJS: {"event":"gaevent","eventparameters":{"category":"TAB","action":":7c:f2, qoslevel=3 11-13 15:45:31.030 961 1618 I HuaweiWifiWatchdogStateMachine: 链接良好报告,良好基础 rssi:-39 11-13 15:45:31.035 388 388 I gralloc: 空闲句柄(0x7f68a42e00) 11 -13 15:45:31.051 388 388 I gralloc:空闲句柄(0x7f68a58400)11-13 15:45:31.132 12692 12738 I ReactNativeJS:[CodePush] 报告状态失败:{“appVersion”:“2.0”} 11-13 15 :45:31.133 12692 12738 I ReactNativeJS:[CodePush]发生未知错误。11-13 15:45:31.134 12692 12738 I ReactNativeJS:[CodePush] 400:更新检查必须包含有效的部署密钥 - 请检查您的应用程序是否已正确配置。要查看可用的部署密钥,请运行“code-push deployment ls -k”。11-13 15:45:31.333 12692 12738 我 ReactNativeJS: {"event":"pageview","page":{"category":" 968 961 961 I TrafficMonitor:启动已过期。级别:-1 11-13 15:45:31.968 961 961 I TrafficMonitor: gettimer:interval=2000 11-13 15:45:32.338 961 1572 E WifiConfigStore: updateConfiguration freq=5200 BSSID=8a:15:14:74:7c :f2 RSSI=-38 "tiptopdev"WPA_PSK 968 961 961 I TrafficMonitor:启动已过期。级别:-1 11-13 15:45:31.968 961 961 I TrafficMonitor: gettimer:interval=2000 11-13 15:45:32.338 961 1572 E WifiConfigStore: updateConfiguration freq=5200 BSSID=8a:15:14:74:7c :f2 RSSI=-38 "tiptopdev"WPA_PSK

任何想法?

谢谢 !

标签: androidreact-nativereact-navigation

解决方案


你应该SplashScreen.hide()componentDidMount()函数中调用。

如果您愿意,可以添加延迟,例如:

import { InteractionManager } from 'react-native';

...

componentDidMount() {

  // Some code here if needed.

  InteractionManager.runAfterInteractions(() => {
    setTimeout(() => {
      SplashScreen.hide();
    }, 750);
  });
}

如果您必须从componentDidUpdate()(因为您需要准备一些数据)调用它,只需调用它,而不是从 if 语句内部。如果启动画面已经消失,SplashScreen.hide()不会造成任何伤害。

(记住这一点 -componentDidUpdate()在第一次渲染后不被调用,仅在第二次渲染之后)


推荐阅读