当前未找到活动。请确保在您的应用程序处于前台时调用此方法。

huangapple go评论95阅读模式
英文:

Current activity not found. Make sure to call this method while your application is in foreground

问题

使用 expo-splash-screen 和 SplashScreen.preventAutoHideAsync() 在生产构建中和在 expo go 上运行应用程序时会引发许多错误。

我在 App.js 中首先调用 preventAutoHideAsync。警告消息是“找不到当前活动。请确保在应用程序在前台运行时调用此方法。”
https://github.com/expo/expo/issues/20502

按照 https://docs.expo.dev/versions/v46.0.0/sdk/splash-screen/ 中的说明进行实施。
可重现的演示:https://github.com/kirtikapadiya/SplashReactNative

英文:

Using expo-splash-screen and SplashScreen.preventAutoHideAsync() throws many errors in production builds and running app on expo go.

I call preventAutoHideAsync first thing in App.js. The warning message is Current activity not found. Make sure to call this method while your application is in foreground.
https://github.com/expo/expo/issues/20502

Implement as per https://docs.expo.dev/versions/v46.0.0/sdk/splash-screen/
Reproducible demo: https://github.com/kirtikapadiya/SplashReactNative

答案1

得分: 1

我不确定这是否会起作用,但我有相同的问题,打算尝试:

// 在我们获取资源时保持启动屏幕可见
SplashScreen.preventAutoHideAsync().catch((error) => {
  // 将事件附加到错误处理系统(Sentry、LogRocket 等)

  // 当应用程序状态为 'active' 时尝试再次调用它
  let attempts = 0;
  const appStateListener = AppState.addEventListener('change', (nextAppState) => {
    if (nextAppState === 'active' && attempts < 3) {
      attempts++;
      SplashScreen.preventAutoHideAsync()
        .then(() => appStateListener.remove())
        .catch((error) => {
          // 将事件附加到错误处理系统(Sentry、LogRocket 等)
        });
    }
    if (attempts >= 3) {
      appStateListener.remove();
    }
  });
})


export default function App() {
  ....
}
英文:

I'm not sure if this will work, but I have the same problem and are gonna try:

// Keep the splash screen visible while we fetch resources
SplashScreen.preventAutoHideAsync().catch((error) =&gt; {
  // Attach the event to error handling system (Sentry, LogRocket etc.)

  // Try to call it again when app state is &#39;active&#39;
  let attempts = 0
  const appStateListener = AppState.addEventListener(&#39;change&#39;, (nextAppState) =&gt; {
    if (nextAppState === &#39;active&#39; &amp;&amp; attempts &lt; 0) {
      attemps++
      SplashScreen.preventAutoHideAsync()
        .then(() =&gt; appStateListener.remove())
        .catch((error) =&gt; {
          // Attach the event to error handling system (Sentry, LogRocket etc.)
        })
    }
    if (attempts &gt;= 3) {
      appStateListener.remove()
    }
  })
})


export default function App() {
  ....

huangapple
  • 本文由 发表于 2023年1月6日 13:13:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75027159.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定