Home | History | Annotate | Download | only in lifecycle
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package androidx.lifecycle;
     18 
     19 import androidx.annotation.NonNull;
     20 
     21 /**
     22  * Callback interface for listening to {@link LifecycleOwner} state changes.
     23  * <p>
     24  * If you use Java 8 language, <b>always</b> prefer it over annotations.
     25  */
     26 @SuppressWarnings("unused")
     27 public interface DefaultLifecycleObserver extends FullLifecycleObserver {
     28 
     29     /**
     30      * Notifies that {@code ON_CREATE} event occurred.
     31      * <p>
     32      * This method will be called after the {@link LifecycleOwner}'s {@code onCreate}
     33      * method returns.
     34      *
     35      * @param owner the component, whose state was changed
     36      */
     37     @Override
     38     default void onCreate(@NonNull LifecycleOwner owner) {
     39     }
     40 
     41     /**
     42      * Notifies that {@code ON_START} event occurred.
     43      * <p>
     44      * This method will be called after the {@link LifecycleOwner}'s {@code onStart} method returns.
     45      *
     46      * @param owner the component, whose state was changed
     47      */
     48     @Override
     49     default void onStart(@NonNull LifecycleOwner owner) {
     50     }
     51 
     52     /**
     53      * Notifies that {@code ON_RESUME} event occurred.
     54      * <p>
     55      * This method will be called after the {@link LifecycleOwner}'s {@code onResume}
     56      * method returns.
     57      *
     58      * @param owner the component, whose state was changed
     59      */
     60     @Override
     61     default void onResume(@NonNull LifecycleOwner owner) {
     62     }
     63 
     64     /**
     65      * Notifies that {@code ON_PAUSE} event occurred.
     66      * <p>
     67      * This method will be called before the {@link LifecycleOwner}'s {@code onPause} method
     68      * is called.
     69      *
     70      * @param owner the component, whose state was changed
     71      */
     72     @Override
     73     default void onPause(@NonNull LifecycleOwner owner) {
     74     }
     75 
     76     /**
     77      * Notifies that {@code ON_STOP} event occurred.
     78      * <p>
     79      * This method will be called before the {@link LifecycleOwner}'s {@code onStop} method
     80      * is called.
     81      *
     82      * @param owner the component, whose state was changed
     83      */
     84     @Override
     85     default void onStop(@NonNull LifecycleOwner owner) {
     86     }
     87 
     88     /**
     89      * Notifies that {@code ON_DESTROY} event occurred.
     90      * <p>
     91      * This method will be called before the {@link LifecycleOwner}'s {@code onStop} method
     92      * is called.
     93      *
     94      * @param owner the component, whose state was changed
     95      */
     96     @Override
     97     default void onDestroy(@NonNull LifecycleOwner owner) {
     98     }
     99 }
    100 
    101