animation - Starting an AnimationDrawable in Android -


Where should I start an animation drawer , whose an action is shown to animate the wanted? Developer guide using

onWindowFocusChanged , but it is always called when activity is not part of TabHost

I bid It is important to keep in mind that the initial method called on the animation drable can not be called during the creative () method of your activity, because the animation dreable is still completely Do not connect to the window if you need interaction Not immediately animation you want to play, then you get your window it may wish to call on window focus Chenged () method in your activity that Android focus.

The parallel thread approach seems most popular, but it enhances the two major issues:

  • According to the docs, all UI related codes should be run on the main (aka "GUI") thread. Calling (start) on animation drainage can not be considered a pure UI operation, I still feel that it should follow that rule.
  • You never know when your animation will start. I have seen the code with "magic" delay length values ​​that were going to fix. You should know that every time a programmer kills God that attitude.

Therefore, I suggest using the very appropriate named runOnUiThread () method. By calling this, the resume will assure you that your animation code will run on the main thread, it will be running after the window is attached, you will know how the message is being processed and the loss of a kitten Not required:

@override resume at zero protected (super.onResume (); RunOnUiThread (New Runnabel) {@Override Public Zero () (animation.start ();}})}}

Comments