diff --git a/entry/src/main/ets/common/utils/CommonUtils.ets b/entry/src/main/ets/common/utils/CommonUtils.ets index f2a3cde8d4920306180b3380b1589d4f5a1f6675..0a49b552bcff7a13c48e2249cf83f2f6e47beeb1 100644 --- a/entry/src/main/ets/common/utils/CommonUtils.ets +++ b/entry/src/main/ets/common/utils/CommonUtils.ets @@ -15,9 +15,11 @@ import { promptAction } from '@kit.ArkUI'; +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); + export class CommonUtils { showToast(message: string | Resource) { - promptAction.showToast({ + uiContext?.getPromptAction().showToast({ message: message, duration: 1000 }); diff --git a/entry/src/main/ets/common/utils/DBUtils.ets b/entry/src/main/ets/common/utils/DBUtils.ets index a4892c01ae32e99ca3b22e90755979e9afd701bb..121131bac247eaeb04e4ca769214e0799bc139eb 100644 --- a/entry/src/main/ets/common/utils/DBUtils.ets +++ b/entry/src/main/ets/common/utils/DBUtils.ets @@ -20,7 +20,7 @@ import { CommonConstants } from '../constants/CommonConstants'; import Logger from './Logger'; let store: relationalStore.RdbStore | undefined = undefined; -let context = getContext(this); +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); const STORE_CONFIG: relationalStore.StoreConfig = { name: "RdbTest.db", securityLevel: relationalStore.SecurityLevel.S1 @@ -37,7 +37,7 @@ export class DBUtils { * Creating a User Table. */ createDB() { - relationalStore.getRdbStore(context, STORE_CONFIG, (err: BusinessError, rdbStore: relationalStore.RdbStore) => { + relationalStore.getRdbStore(uiContext?.getHostContext(), STORE_CONFIG, (err: BusinessError, rdbStore: relationalStore.RdbStore) => { store = rdbStore; if (store !== undefined) { (store as relationalStore.RdbStore).executeSql(CommonConstants.SQL_CREATE_USER_TABLE, (err) => { diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 8bd1dd3bfc74906b9c7d9d2b22d2b67fc3de24ec..bfbb5e157ef04b78e0cbb2a76970b687eeb36698 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -31,6 +31,7 @@ export default class EntryAbility extends UIAbility { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); windowStage.loadContent('pages/Index', (err, data) => { + AppStorage.setOrCreate('uiContext', windowStage.getMainWindowSync().getUIContext()); if (err.code) { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return;