任务背景

任务描述

两层结构:commons和Entry

训练目标

实现思路

  1. 应用icon配置
  • new一个Image Asset。并设置foreground为所用icon,这样可以生成各种分辨率的icon
  • Hap的module.json5->abilities->label(ctrl+b进去设置foreground)、startWindowIcon两个都改成自己的icon
  1. 广告跳转与窗口管理
  • commons中设置数据类、api、常量
  • entry中设置entryAbility
async onWindowStageCreate(windowStage: window.WindowStage): Promise<void> {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
let ad = await getAdInfo()
let userInfo:UserSettings = new UserSettings(this.context)
userInfo.setAd(ad)
//若有广告
if(ad.showAd){
//创建窗口
let subWin = await windowStage.createSubWindow('subWin')
//显示广告页的窗口
subWin.showWindow()
subWin.setUIContent('pages/Start/AdPage')
}
else {}
//上面的执行完后执行下面这句,从而跳转到login页
windowStage.loadContent('pages/login/LoginPage', (err) => {}
  • 广告页中操纵广告窗口生命周期
aboutToAppear(): void {
let userInfo:UserSettings = new UserSettings(getContext())
this.ad = userInfo.getAd()
this.timeCnt = this.ad.adTime
}
onPageShow(): void {
this.taskId = setInterval(()=>{
--this.timeCnt
if(this.timeCnt <= 0)
{
window.findWindow('subWin').destroyWindow()
clearInterval(this.taskId)
}
},1000)
}

问题与解决方案

问题 解决方案

优化

待优化方向

具体优化思路

参考答案分析

总结