Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 088fa35

Browse files
authored
Merge pull request #72 from shreelakshmijoshi/AnimatedVectorDrawableCompat-61
Fixing App Crash When Back Key Pressed During Animations
2 parents 1b8de3f + f37a0ba commit 088fa35

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

DrawableAnimations/app/src/main/java/com/example/android/drawableanimations/demo/animated/AnimatedFragment.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,19 @@ class AnimatedFragment : Fragment(R.layout.animated_fragment) {
3030

3131
private val binding by viewBindings(AnimatedFragmentBinding::bind)
3232

33+
override fun onDestroyView() {
34+
super.onDestroyView()
35+
(binding.icon.drawable as? AnimatedVectorDrawableCompat)?.clearAnimationCallbacks()
36+
}
37+
3338
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
39+
3440
val icon = AnimatedVectorDrawableCompat.create(
3541
requireContext(),
3642
R.drawable.ic_hourglass_animated
3743
)!!
38-
icon.registerAnimationCallback(object: Animatable2Compat.AnimationCallback() {
44+
45+
icon.registerAnimationCallback(object : Animatable2Compat.AnimationCallback() {
3946
override fun onAnimationStart(drawable: Drawable?) {
4047
binding.start.isEnabled = false
4148
binding.stop.isEnabled = true

DrawableAnimations/app/src/main/java/com/example/android/drawableanimations/demo/seekable/SeekableFragment.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import android.os.Bundle
2020
import android.view.View
2121
import android.widget.SeekBar
2222
import androidx.fragment.app.Fragment
23+
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
2324
import androidx.vectordrawable.graphics.drawable.SeekableAnimatedVectorDrawable
2425
import com.example.android.drawableanimations.R
2526
import com.example.android.drawableanimations.databinding.SeekableFragmentBinding
@@ -29,6 +30,11 @@ class SeekableFragment : Fragment(R.layout.seekable_fragment) {
2930

3031
private val binding by viewBindings(SeekableFragmentBinding::bind)
3132

33+
override fun onDestroyView() {
34+
super.onDestroyView()
35+
(binding.icon.drawable as? AnimatedVectorDrawableCompat)?.clearAnimationCallbacks()
36+
}
37+
3238
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
3339
// You can use the same XML format of <animated-vector> to inflate a
3440
// SeekableAnimatedVectorDrawable.

0 commit comments

Comments
 (0)