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