Step 1. Add the JitPack repository to your build file:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency:
dependencies {
implementation 'com.github.restorer:holycycle:0.2.1@aar'
}
This library is an abstraction over Activity or Fragment lifecycle, which makes it more straightforward and consistent.
↓ onControllerCreate(Bundle extras)
? onControllerRestoreInstanceState(Bundle savedInstanceState)
↓ onControllerGetContentLayoutId()
↓ onControllerContentViewCreated()
↓ onControllerStart()
↓ onControllerResume()
↓ onControllerFocus()
↓ onControllerBlur()
↓ onControllerPause()
↓ onControllerPersistUserData()
↓ onControllerStop()
? onControllerSaveInstanceState(Bundle outState)
This is similar to the standard lifecycle callbacks, but has several advantages:
- Workaround for
onSaveInstanceState()
- library guarantees thatonControllerBlur()
,onControllerPause()
,onControllerPersistUserData()
andonControllerStop()
will be called prior toonControllerSaveInstanceState()
. Say goodbye tojava.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
😃. - The same methods for Activity and Fragment (unless you use
setRetainInstance(true)
, but please don't use it). onControllerFocus()
/onControllerBlur()
out of the box, and perfectly synced withonControllerResume()
/onControllerPause()
(vsonWindowFocusChanged()
).getView()
for Activity (just like Fragment).findViewById()
for Fragment (just like Activity).