中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
HarmonyOS 让app回到后台(桌面)的系统方法。
微信扫码分享
import window from '@ohos.window' import { BusinessError } from '@ohos.base'; @Entry @Component struct Page240605161307072 { @State message: string = 'Hello World'; onBackPress() { const context = getContext(this) window.getLastWindow(getContext()).then((data) => { //获取窗口对象 let windowClass = data; windowClass.minimize((err: BusinessError) => { const errCode: number = err.code; if (errCode) { console.error('Failed to minimize the window. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in minimizing the window.'); }); console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); }); return true; } build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) TextInput() } .width('100%') } .height('100%') } }