Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AnimationDrawable in Android problem

I am having a common problem doing animationdrawable in Android. I wanted to start an animation when the Activity starts, in the onCreate() method, but as many people have found, it doesn't work.

I have read lots of advice but nothing seems to work for me. If I start the animation in onClick() it works, it requires user input, not starting immediately.

I tried starting it in a separate thread in onCreate() but that doesn't work either. I read here:

http://code.google.com/p/android/issues/detail?id=1818

but none of the advice worked, or I couldn't understand it.

Can someone help?

like image 608
Jon Smith Avatar asked Oct 14 '22 21:10

Jon Smith


1 Answers

I've faced similar problems, and switched to overriding onWindowFocusChanged() instead of onCreate() and onResume():

public void onWindowFocusChanged(boolean hasFocus) 
{
    if (hasFocus)
    {
        animation.start();
    }
    else
    {   
        animation.stop();
    }
}
like image 82
Vaiden Avatar answered Oct 18 '22 03:10

Vaiden