0

just simple question I have an animation where I should put them ? in On-create or in On-resume or where ? so that when I pause the activity the animation is paused .. not played in background ! and when I resume the Activity the animation resumes .. not start from zero ! ?

my animation is like that :

view.startAnimation(AnimationUtils.loadAnimation(this, R.anim.slide);
  • 1
    Do you know how to pause/resume the animation? – Peter Sep 24 '17 at 22:16
  • You should probably start the animation in Activity.onStart and pause it in Activity.onStop. An activity is considered visible/started once onStart has been called – Peter Sep 24 '17 at 22:18
  • I have read how to pause and resume animation using Animator .. so should I convert all my animation to Animator .. and it only supports minSdkVersion 19 ! – Hosain Mohamed Sep 24 '17 at 22:19

1 Answers1

0

You should stop your animation in onPause() and start your animation again in onResume()

Check out this Activity Lifecycle diagram to guide you :)

enter image description here

onPause is invoked when a popup appears and the Activity is partly visible. After the popup is removed, then onResume is invoked. When Activity is hidden and shown again later, those methods are again invoked, so they are your best choise.

About starting and stopping animations - this article should help you

About pausing animation - this article should help you

Krasimir Stoev
  • 1,644
  • 10
  • 9
  • I dont know how to pause and then resuming the animation – Hosain Mohamed Sep 24 '17 at 22:21
  • This article should help you on starting and stopping animation: https://stackoverflow.com/questions/9400705/starting-and-stopping-animation – Krasimir Stoev Sep 24 '17 at 22:23
  • it talks about stopping animation not not resuming ! – Hosain Mohamed Sep 24 '17 at 22:26
  • to resume the animation, simply start it again – Krasimir Stoev Sep 24 '17 at 22:29
  • I have tried that protected void onResume() { super.onResume(); view.startAnimation(xxx); } protected void onPause() { super.onPause(); view.clearAnimation(); } and it begans the animation from 0 again ! – Hosain Mohamed Sep 24 '17 at 22:40
  • I think it's stopping the animation not pausing it !! is there a way to pause animation or pause method contain animation and then resuming it ?? – Hosain Mohamed Sep 24 '17 at 22:41
  • well then i guess this article would help: https://stackoverflow.com/questions/2864488/how-do-i-pause-frame-animation-using-animationdrawable/7840895#7840895 – Krasimir Stoev Sep 24 '17 at 22:44
  • that's works for Animation class not from animation in my res file like R.anim.slide .. thanks for ur help @Krasimir .. is there any way in that world to pause animation in which in my res file ? – Hosain Mohamed Sep 24 '17 at 22:52