1

When I launch the emulator, the animation only plays the first frame of the animation, sits for the duration of the timer and then starts the activity.

This is my Drawable xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/title1" android:duration="200" />
<item android:drawable="@drawable/title2" android:duration="200" />
<item android:drawable="@drawable/title3" android:duration="200" />
<item android:drawable="@drawable/title4" android:duration="200" />
<item android:drawable="@drawable/title5" android:duration="200" />
<item android:drawable="@drawable/title6" android:duration="200" />
<item android:drawable="@drawable/title7" android:duration="200" />
<item android:drawable="@drawable/title8" android:duration="200" />
<item android:drawable="@drawable/title9" android:duration="200" />
<item android:drawable="@drawable/title10" android:duration="200" />
<item android:drawable="@drawable/title11" android:duration="200" />
</animation-list>

This is my layout xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
 >

<ImageView
android:id="@+id/gyro"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
 />

This is my java file

 public void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);
    // Start the animation (looped playback by default).
    ImageView splash = (ImageView) findViewById(R.id.gyro);
    splash.setBackgroundResource(R.drawable.title);
    AnimationDrawable splashAnimation = (AnimationDrawable) splash.getBackground();
    splashAnimation.start();


    Thread logoTimer = new Thread(){
        public void run(){
        try{
        int logoTimer = 0;
            while(logoTimer <10000){
            sleep(100);
            logoTimer = logoTimer + 100;
            }//end of while loop
            //mpsplash.stop();
            startActivity(new Intent("tv.bScienceFiction.scrip.or.scrap.CLEARSCREEN"));
            } catch (InterruptedException e) {
                //TODO Auto-generated catch block
                e.printStackTrace();
            }

        finally{
            finish();
        }//end of finally

        }//end of run

    };//end of new Thread
    logoTimer.start();
}

1 Answers1

0

Start it from the UI thread after you exit onCreate

   splash.postDelayed(new Runnable() {
      public void run() {
         splashAnimation.start();
      }
   }, 200);
msh
  • 2,700
  • 1
  • 17
  • 23
  • You are awesome. That worked perfectly. thank you. I had been beating my head against a wall. Every tutorial I could find did not address that. Thank you. – bScienceFiction.tv May 29 '13 at 13:36
  • 1
    If this solution is working for you, please mark it as "accepted" - that would help other people find it should they have the same question – msh May 29 '13 at 14:07