Forked from vishalratna-microsoft/LazyLifecycleCallbacks.kt
Created
June 23, 2022 11:04
-
-
Save belinwu/1a9f48ad8df664e8f63f8624c9f3d4bb to your computer and use it in GitHub Desktop.
LazyLifecycleCallbacks contract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.view.View | |
interface LazyLifecycleCallbacks { | |
/** | |
* Lazy version of activity onCreate() callback. Should be used for one time initialisations that could be done after the | |
* screen has finished rendering. Should not be used for complementary calls that set/reset their state in | |
* onCreate/onDestroy | |
*/ | |
fun onLazyCreate() | |
/** | |
* Lazy version of activity onStart() callback. Should be used for initialisations and code that are non essential and can be | |
* deferred till the activity has finished rendering. Just like onCreate() this should not be used for complementary calls | |
* like registering a broadcast receiver in onStart() and unregistering in onStop(). For these kinds of use cases use | |
* activity lifecycle methods. This can be used for cases, like updating a bitmap every time apps come to foreground from background, | |
* making some n/w, db calls to refresh the data, some initialisations of classes etc. | |
*/ | |
fun onLazyStart() | |
/** | |
* See onLazyStart() documentation. | |
*/ | |
fun onLazyResume() | |
/** | |
* Returns if the current activity supports lazy lifecycle callbacks. | |
* If this method returns false, then even if the activity overrides the lazy callbacks | |
* it does not have any impact. | |
* The individual activities have to onboard this by returning true. | |
*/ | |
fun supportsLazyLifecycleCallbacks(): Boolean | |
/** | |
* The view that will be observed by the [LazyLifecycleManager] for draw events. | |
*/ | |
val watchedView: View | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment