• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "ability_lifecycle_observer.h"
17 
18 namespace OHOS {
19 namespace AppExecFwk {
20 /**
21  * @brief Called back in response to an ON_ACTIVE event.
22  * When an ON_ACTIVE event is received, the ability or ability slice is in the foreground and is interactive.
23  */
OnActive()24 void LifecycleObserver::OnActive()
25 {}
26 
27 /**
28  * @brief Called back in response to an ON_BACKGROUND event.
29  * When an ON_BACKGROUND event is received, the ability or ability slice is invisible. You are advised to
30  * suspend the threads related to this ability or ability slice and clear resources for more system memory.
31  *
32  */
OnBackground()33 void LifecycleObserver::OnBackground()
34 {}
35 
36 /**
37  * @brief Called back in response to an ON_FOREGROUND event, where information for the
38  * ability or ability slice to go back to the ACTIVE state is carried in the want parameter.
39  * When an ON_FOREGROUND event is received, the ability or ability slice returns to the foreground. You can use
40  * this method to implement re-initialization or adjust the UI display by using the want parameter.
41  *
42  * @param want Indicates the information for the ability or ability slice to go back to the ACTIVE state.
43  */
OnForeground(const Want & want)44 void LifecycleObserver::OnForeground(const Want &want)
45 {}
46 
47 /**
48  * @brief Called back in response to an ON_INACTIVE event.
49  * When an ON_INACTIVE event is received, the ability or ability slice is in the INACTIVE state. INACTIVE is an
50  * intermediate state before the state changes to ACTIVE or BACKGROUND. In this state, the UI may be visible but is
51  * not interactive. You are advised not to use this method to invoke complex service logic.
52  *
53  */
OnInactive()54 void LifecycleObserver::OnInactive()
55 {}
56 
57 /**
58  * @brief Called back in response to an ON_START event, where the startup information
59  * is carried in the want parameter.
60  * This method initializes an Ability or AbilitySlice and is called back only once during the entire lifecycle.
61  * You are advised to implement some initialization logic using this method, for example, you can initialize a
62  * timer or define some global objects.
63  *
64  * @param want Indicates the startup information.
65  */
OnStart(const Want & want)66 void LifecycleObserver::OnStart(const Want &want)
67 {}
68 
69 /**
70  * @brief Called back in response to an ON_STOP event.
71  * This method is called back when the lifecycle of the ability or ability slice is destroyed. You can reclaim
72  * resources using this method.
73  *
74  */
OnStop()75 void LifecycleObserver::OnStop()
76 {}
77 
78 /**
79  * @brief Called back in response to a lifecycle change. This method is triggered by a registered LifecycleObserver
80  * each time the lifecycle state changes.
81  *
82  * @param event Indicates the lifecycle event.
83  * @param want Indicates the state change information.
84  */
OnStateChanged(Lifecycle::Event event,const Want & want)85 void LifecycleObserver::OnStateChanged(Lifecycle::Event event, const Want &want)
86 {}
87 
88 /**
89  * @brief Called back in response to a lifecycle change. This method is triggered by a registered LifecycleObserver
90  * each time the lifecycle state changes.
91  *
92  * @param event Indicates the lifecycle event.
93  */
OnStateChanged(LifeCycle::Event event)94 virtual void LifecycleObserver::OnStateChanged(LifeCycle::Event event)
95 {}
96 }  // namespace AppExecFwk
97 }  // namespace OHOS