英文:
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) => {
// Attach the event to error handling system (Sentry, LogRocket etc.)
// Try to call it again when app state is 'active'
let attempts = 0
const appStateListener = AppState.addEventListener('change', (nextAppState) => {
if (nextAppState === 'active' && attempts < 0) {
attemps++
SplashScreen.preventAutoHideAsync()
.then(() => appStateListener.remove())
.catch((error) => {
// Attach the event to error handling system (Sentry, LogRocket etc.)
})
}
if (attempts >= 3) {
appStateListener.remove()
}
})
})
export default function App() {
....
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论