Challenge: Saving State - Boxes

These 2 functions didn’t do anything when i rotated the screen

override fun onSaveInstanceState(): Parcelable? {
        return super.onSaveInstanceState()
    }

    override fun onRestoreInstanceState(state: Parcelable?) {
        super.onRestoreInstanceState(state)
    }

also Android studio didn’t allow me to use protected for them…

anyway what worked for me was

 override fun onDetachedFromWindow() {
        super.onDetachedFromWindow()
    }

    override fun onAttachedToWindow() {
        super.onAttachedToWindow()

    }

i didn’t look around to do with Parcelable to be honest…

but for such situation i would divide the points of the boxen into Float Arrays and combine them after configuration change.

        boxen.forEach {
            println("Box= ${it.left}, ${it.top}, ${it.right}, ${it.bottom}, ${it.end}, ${it.start}")
        }

PS.I know this is for printing…

Can you share the full solution?

i don’t know where it is to be honest…

1 Like