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