1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import UIAbility from '@ohos.app.ability.UIAbility'; 17import window from '@ohos.window'; 18import Logger from '../model/Logger'; 19 20const TAG = '[Sample_EntryAbility]'; 21 22export default class EntryAbility extends UIAbility { 23 onCreate(want, launchParam) { 24 Logger.info(TAG, `onCreate, want: ${JSON.stringify(want)},`, `launchParam: ${JSON.stringify(launchParam)}`); 25 let flag = (typeof(want.parameters.sharedFlag) === 'boolean') ? want.parameters.sharedFlag : false; 26 AppStorage.SetOrCreate('messages', want.parameters.shareMessages); 27 AppStorage.SetOrCreate('sharedFlag', flag); 28 } 29 30 onNewWant(want, launchParam) { 31 Logger.info(TAG, `onNewWant, want: ${JSON.stringify(want)},`, `launchParam: ${JSON.stringify(launchParam)}`); 32 let flag = (typeof(want.parameters.sharedFlag) === 'boolean') ? want.parameters.sharedFlag : false; 33 AppStorage.SetOrCreate('messages', want.parameters.shareMessages); 34 AppStorage.SetOrCreate('sharedFlag', flag); 35 } 36 37 onDestroy() { 38 Logger.info(TAG, 'onDestroy'); 39 } 40 41 onWindowStageCreate(windowStage: window.WindowStage) { 42 Logger.info(TAG, `onWindowStageCreate, windowStage: ${JSON.stringify(windowStage)}`); 43 44 windowStage.loadContent('pages/Index', (err, data) => { 45 if (err.code) { 46 Logger.error(TAG, `Failed to load the content, Cause: ${JSON.stringify(err)}`); 47 return; 48 } 49 Logger.info(TAG, `Succeeded in loading the content, Data: ${JSON.stringify(data)}`); 50 }); 51 } 52 53 onWindowStageDestroy() { 54 Logger.info(TAG, 'onWindowStageDestroy'); 55 } 56 57 onForeground() { 58 Logger.info(TAG, 'onForeground'); 59 } 60 61 onBackground() { 62 Logger.info(TAG, 'onBackground'); 63 } 64} 65