应用每次启动后都会长时间停留在闪屏页。


import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct LongSplashPage {
message: string = `我是闪屏页,10秒后我将跳转登录页`;
onPageShow(): void {
setTimeout(() => {
this.getUIContext().getRouter().pushUrl({
url: 'pages/Index' // 目标url
}).catch((error: BusinessError) => {
console.error(`jump error: ${error.code}, ${error.message}`);
});
}, 10000); // 设置10s后跳转
}
build() {
RelativeContainer() {
Text(this.message)
.id('LongSplashPageHelloWorld')
.fontSize($r('app.float.page_text_font_size'))
.fontWeight(FontWeight.Bold)
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
.onClick(() => {
this.message = 'Welcome';
});
}
.height('100%')
.width('100%');
}
} 应用通过定时器设置了从闪屏页跳转登录页的固定时间,这个固定时间过长造成了在闪屏页的停留时间过长。
应用酌情减少定时器设置的时间,避免用户长时间等待。
闪屏页设置:
@Entry
@Component
struct ShortSplashPage {
message: string = `我是闪屏页,5秒后我将跳转登录页`;
onPageShow(): void {
setTimeout(() => {
this.getUIContext().getRouter().pushUrl({
url: 'pages/Index' // 目标url
}).catch((error: BusinessError) => {
console.error(`jump error: ${error.code}, ${error.message}`);
});
}, 5000); // 设置5s后跳转
}
build() {
RelativeContainer() {
Text(this.message)
.id('ShortSplashPageHelloWorld')
.fontSize($r('app.float.page_text_font_size'))
.fontWeight(FontWeight.Bold)
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
.onClick(() => {
this.message = 'Welcome';
});
}
.height('100%')
.width('100%');
}
} 登录页:
@Entry
@Component
struct Index {
@State message: string = '我是登录页';
build() {
RelativeContainer() {
Text(this.message)
.id('HelloWorld')
.fontSize($r('app.float.page_text_font_size'))
.fontWeight(FontWeight.Bold)
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
.onClick(() => {
this.message = 'Welcome';
});
}
.height('100%')
.width('100%');
}
} 合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功