• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Dagger Authors.
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 dagger.hilt.android;
18 
19 import android.app.Activity;
20 import androidx.annotation.MainThread;
21 import androidx.annotation.NonNull;
22 
23 /**
24  * A <code>ActivityRetainedLifecycle</code> class is associated with the lifecycle of the {@link
25  * dagger.hilt.android.components.ActivityRetainedComponent}.
26  */
27 public interface ActivityRetainedLifecycle {
28 
29   /**
30    * Adds a new {@link OnClearedListener} for receiving a callback when the activity retained
31    * instances will no longer be needed and destroyed.
32    *
33    * @param listener The listener that should be added.
34    */
35   @MainThread
addOnClearedListener(@onNull OnClearedListener listener)36   void addOnClearedListener(@NonNull OnClearedListener listener);
37 
38   /**
39    * Removes a {@link OnClearedListener} previously added via {@link
40    * #addOnClearedListener(OnClearedListener)}.
41    *
42    * @param listener The listener that should be removed.
43    */
44   @MainThread
removeOnClearedListener(@onNull OnClearedListener listener)45   void removeOnClearedListener(@NonNull OnClearedListener listener);
46 
47   /**
48    * Listener for receiving a callback for when the {@link
49    * dagger.hilt.android.components.ActivityRetainedComponent} will no longer be used and destroyed.
50    */
51   interface OnClearedListener {
52 
53     /**
54      * Called when the activity retained instances will no longer be used and destroyed.
55      *
56      * <p>Specifically this will be invoked during {@link Activity#onDestroy()} when {@link
57      * Activity#isChangingConfigurations} is false.
58      */
onCleared()59     void onCleared();
60   }
61 }
62