Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in sample DrawableAnimations on exiting AnimatedVectorDrawableCompat #61

Closed
amazingvoice opened this issue Jul 21, 2021 · 7 comments

Comments

@amazingvoice
Copy link

Steps to observe this issue:
start the app DrawableAnimations -> click AnimatedVectorDrawableCompat -> click START -> back press before the animation is done

crash stacktrace:
java.lang.IllegalStateException: Fragment AnimatedFragment{50ea0d2} (32e3cce7-653f-446c-8e11-15e585368791)} did not return a View from onCreateView() or this was called before onCreateView().
at androidx.fragment.app.Fragment.requireView(Fragment.java:1780)
at com.example.android.drawableanimations.demo.animated.AnimatedFragment$$special$$inlined$viewBindings$1.getValue(ViewBindingDelegates.kt:50)
at com.example.android.drawableanimations.demo.animated.AnimatedFragment$$special$$inlined$viewBindings$1.getValue(ViewBindingDelegates.kt:39)
at com.example.android.drawableanimations.demo.animated.AnimatedFragment.getBinding(Unknown Source:2)
at com.example.android.drawableanimations.demo.animated.AnimatedFragment.access$getBinding$p(AnimatedFragment.kt:29)
at com.example.android.drawableanimations.demo.animated.AnimatedFragment$onViewCreated$1.onAnimationEnd(AnimatedFragment.kt:45)
at androidx.vectordrawable.graphics.drawable.Animatable2Compat$AnimationCallback$1.onAnimationEnd(Animatable2Compat.java:86)
at android.graphics.drawable.AnimatedVectorDrawable$2.onAnimationEnd(AnimatedVectorDrawable.java:1021)
at android.graphics.drawable.AnimatedVectorDrawable$VectorDrawableAnimatorRT.onAnimationEnd(AnimatedVectorDrawable.java:1771)
at android.graphics.drawable.AnimatedVectorDrawable$VectorDrawableAnimatorRT.lambda$callOnFinished$0(AnimatedVectorDrawable.java:1778)
at android.graphics.drawable.AnimatedVectorDrawable$VectorDrawableAnimatorRT$$ExternalSyntheticLambda0.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7829)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:982)

@shreelakshmijoshi
Copy link
Contributor

Hi @amazingvoice !
I am a new open source contributor and would like to solve this issue, could you help me understand the issue better by providing some extra references ?
Is this is issue open to contribute ?

@amazingvoice
Copy link
Author

Hi @shreelakshmijoshi! Just run the demo DrawableAnimations on any android phone or emulator, follow the steps I provided:

start the app DrawableAnimations -> click AnimatedVectorDrawableCompat -> click START -> back press before the animation is done,

then check the logcat to find the stacktrace, you can set some breakpoints to help you understand how it works.

@shreelakshmijoshi
Copy link
Contributor

shreelakshmijoshi commented Aug 25, 2021

The animated fragment is set to null after the animation is completed. When we press the back button , the view gets destroyed but the animated fragment which is bound to the view is still running. We should also destroy the object associated with the view when back button is pressed.
That's why OnBackPressedCallback function is added which implements the operation of the stop button

 override fun onAttach(context: Context){
       super.onAttach(context)
       val callback: OnBackPressedCallback =object:OnBackPressedCallback(
       true
       ){
           override fun handleOnBackPressed(){
               binding.stop.performClick()
               activity?.supportFragmentManager?.popBackStack()
           }
       }
       requireActivity().onBackPressedDispatcher.addCallback(
           this,
           callback
       )
   }

@shreelakshmijoshi
Copy link
Contributor

@amazingvoice please review my pull request link

@amazingvoice
Copy link
Author

@shreelakshmijoshi Sorry I'm not the maintainer of this project.
@ggfan Please help review this PR. Thanks!

@shreelakshmijoshi
Copy link
Contributor

oh okay..

@shreelakshmijoshi
Copy link
Contributor

@ggfan
Can you or someone else help me review and merge the pull request ?
Thank You!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants