Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8324789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:12:08+00:00 2026-06-09T00:12:08+00:00

I am having trouble getting my button animation to run when my activity starts

  • 0

I am having trouble getting my button animation to run when my activity starts up, I am sorta new here and any suggestion will be grateful. Here is what I have at the beginning of my Activity…..

    // this is flag for home key press
public static boolean isHome = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.press);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);



    // init data
    init();

    // start player display
    start(10000 * 60 * 60 * 24);

    spin++;

    // play background music
    playmp3(R.raw.press);
 }
//HERE IS THE WORKING VERSION THAT WAS CORRECTED BY THE ANSWER BELOW
 public void onWindowFocusChanged(boolean hasFocus) {
     super.onWindowFocusChanged(hasFocus);

     if(hasFocus) {
     final Button b_1 = (Button) findViewById(R.id.bttest);
         b_1.setBackgroundResource(R.drawable.animation);
         AnimationDrawable b1Amin = (AnimationDrawable) b_1.getBackground();
     b1Amin.start();
    }
 }

and here is my animation.xml in my drawable file

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
  android:oneshot="false">
<item android:drawable="@drawable/btn1" android:duration="100" />
<item android:drawable="@drawable/btn2" android:duration="100" />
<item android:drawable="@drawable/btn3" android:duration="100" />
<item android:drawable="@drawable/btn4" android:duration="100" />
<item android:drawable="@drawable/btn5" android:duration="100" />
<item android:drawable="@drawable/btn6" android:duration="100" />
<item android:drawable="@drawable/btn7" android:duration="100" />
<item android:drawable="@drawable/btn8" android:duration="100" />

</animation-list>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:12:11+00:00Added an answer on June 9, 2026 at 12:12 am

    The API documentation for AnimationDrawable#start() explicitly states that it should not be invoked from onCreate(Bundle) since the AnimationDrawable has not been attached to the window yet. Follow the advice in the docs and invoke start() from onWindowFocusChanged(boolean) instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble getting the new feature released by Spotify, Play Button, to
im having trouble getting a string (containing a URL) from one activity to another.
I'm having trouble getting OpenGL 3.2 to run on Lion (osx 10.7.4) using Derelict3
I'm having some trouble getting my button text to align correctly in my Android
I am having trouble getting the new .on click to work using 1.7. For
I am currently having trouble getting rid of a sliver of white... Here is
I'm having trouble getting tinyMCE to work with the new jQuery 1.4.2 on IE6.
I'm having trouble getting this button to only appear under the drawer. I'm using
I'm having trouble getting an ASP button to call a jquery script, in this
I'm having trouble getting my CSS 3 button to operate properly. You can view

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.