1 /* 2 * Copyright (c) 2021-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 16 #ifndef OHOS_ABILITY_RUNTIME_ABILITY_LIFECYCLE_CALLBACK_H 17 #define OHOS_ABILITY_RUNTIME_ABILITY_LIFECYCLE_CALLBACK_H 18 19 #include "pac_map.h" 20 21 namespace OHOS { 22 namespace AbilityRuntime { 23 class UIAbility; 24 } 25 namespace AppExecFwk { 26 class AbilityLifecycleCallbacks { 27 public: 28 AbilityLifecycleCallbacks() = default; 29 virtual ~AbilityLifecycleCallbacks() = default; 30 31 /** 32 * 33 * Will be called when the given ability calls Ability->onStart 34 * 35 * @param Ability Indicates the ability object that calls the onStart() method. 36 */ 37 virtual void OnAbilityStart(const std::shared_ptr<AbilityRuntime::UIAbility> &ability) = 0; 38 39 /** 40 * 41 * Will be called when the given ability calls Ability->onInactive 42 * 43 * @param Ability Indicates the Ability object that calls the onInactive() method. 44 */ 45 virtual void OnAbilityInactive(const std::shared_ptr<AbilityRuntime::UIAbility> &ability) = 0; 46 47 /** 48 * 49 * Will be called when the given ability calls Ability->onBackground 50 * 51 * @param Ability Indicates the Ability object that calls the onBackground() method. 52 */ 53 virtual void OnAbilityBackground(const std::shared_ptr<AbilityRuntime::UIAbility> &ability) = 0; 54 55 /** 56 * 57 * Will be called when the given ability calls Ability->onForeground 58 * 59 * @param Ability Indicates the Ability object that calls the onForeground() method. 60 */ 61 virtual void OnAbilityForeground(const std::shared_ptr<AbilityRuntime::UIAbility> &ability) = 0; 62 63 /** 64 * 65 * Will be called when the given ability calls Ability->onActive 66 * 67 * @param Ability Indicates the Ability object that calls the onActive() method. 68 */ 69 virtual void OnAbilityActive(const std::shared_ptr<AbilityRuntime::UIAbility> &ability) = 0; 70 71 /** 72 * 73 * Will be called when the given ability calls Ability->onStop 74 * 75 * @param Ability Indicates the Ability object that calls the onStop() method. 76 */ 77 virtual void OnAbilityStop(const std::shared_ptr<AbilityRuntime::UIAbility> &ability) = 0; 78 79 /** 80 * 81 * Will be Called when an ability calls Ability#onSaveAbilityState(PacMap). 82 * 83 * @param outState Indicates the PacMap object passed to the onSaveAbilityState() callback. 84 */ 85 virtual void OnAbilitySaveState(const PacMap &outState) = 0; 86 }; 87 } // namespace AppExecFwk 88 } // namespace OHOS 89 #endif // OHOS_ABILITY_RUNTIME_ABILITY_LIFECYCLE_CALLBACK_H 90