Skip to content

Instantly share code, notes, and snippets.

@vishalratna-microsoft
Created April 5, 2022 09:08
Show Gist options
  • Save vishalratna-microsoft/fccdd8e0619f81b7386d2dcec56f9219 to your computer and use it in GitHub Desktop.
Save vishalratna-microsoft/fccdd8e0619f81b7386d2dcec56f9219 to your computer and use it in GitHub Desktop.
LazyLifecycleCallbacks contract
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