Prerequisite: Other Foldable Devices (ex. Samsung Fold 2)
Steps to reproduce:
- Open the FragmentsHandler Sample on multi window mode on other foldable devices (ex. Samsung Fold 2)
- Rotate the device a couple of times
- Change the app to cover the entire display area
Expectation: The DualStartFragment and DualEndFragment are visible
Actual: The SingleScreenFragment and DualEndFragment are visible
Cause: onActivityPreCreated lifecycle callback is called twice from time to time
Possible Solution:
// Other companion properties and functions
private const val PRE_CREATED_CALL_DELAY = 500
// Other properties
private var lastActivityPreCreatedTimestamp = System.currentTimeMillis() - PRE_CREATED_CALL_DELAY
override fun onActivityPreCreated(activity: Activity, savedInstanceState: Bundle?) {
val currentTimestamp = System.currentTimeMillis()
if (currentTimestamp - lastActivityPreCreatedTimestamp < PRE_CREATED_CALL_DELAY) {
super.onActivityPreCreated(activity, savedInstanceState)
return
}
// .....
}