• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * @file Describe the file
3 * Copyright (c) 2023 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import UIAbility from '@ohos.app.ability.UIAbility';
18import { Log } from '@ohos/common/src/main/ets/utils/Log'
19import Want from '@ohos.app.ability.Want';
20import window from '@ohos.window';
21import { BusinessError } from '@ohos.base';
22import { GlobalThis } from '@ohos/common/src/main/ets/utils/GlobalThis';
23
24const TAG = 'MainAbility';
25
26export default class MainAbility extends UIAbility {
27  onCreate(want: Want) {
28    Log.log(TAG, "MainAbility onCreate");
29  }
30
31  onDestroy() {
32    Log.log(TAG, "MainAbility onDestroy");
33  }
34
35  onWindowStageCreate(windowStage: window.WindowStage) {
36    // Main window is created, set main page for this ability
37    Log.log(TAG, "MainAbility onWindowStageCreate");
38
39    windowStage.loadContent("pages/index", (err: BusinessError, data) => {
40      if (err.code) {
41        Log.error(TAG, 'Failed to load content. Cause: ' + JSON.stringify(err) ?? '');
42        return;
43      }
44      Log.info(TAG, 'Success in loading the content. Data: ' + JSON.stringify(data) ?? '');
45    });
46    GlobalThis.setUiAbilityContext(this.context);
47  }
48
49  onWindowStageDestroy() {
50    // Main window is destroyed, release UI related resources
51    Log.log(TAG, "MainAbility onWindowStageDestroy");
52  }
53
54  onForeground() {
55    // Ability has brought to foreground
56    Log.log(TAG, "MainAbility onForeground");
57  }
58
59  onBackground() {
60    // Ability has back to background
61    Log.log(TAG, "MainAbility onBackground");
62  }
63};
64