I have a loading screen which closes after 5 secounds and then the app starts. During the loading screen I want to have a frame by frame animation running on top of the background loading screen image. It’s a simple concept an has been used before by many applactions, i’m just not sure how to do it since i’m new to android and programming all together. Below is the code to the splash.java screen and i’ll include the code to the frenchsilk.java class so you can see how the animation works without any other code. (Yes the animation works already BY ITSELF ONLY SO FAR).
Splash.java
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity {
MediaPlayer ourSong;
@Override
protected void onCreate(Bundle PieLovesPie) {
// TODO Auto-generated method stub
super.onCreate(PieLovesPie);
setContentView(R.layout.splash);
ourSong = MediaPlayer.create(Splash.this, R.raw.sound2);
ourSong.start();
Thread timer = new Thread(){
public void run(){
try{
sleep(4800);
} catch (InterruptedException e){
e.printStackTrace();
}finally{
*I shortened these* Intent open"appname" = new Intent"packageNameCode"
*2 lines for space resonse* startActivity(open"appname");
}
}
};
timer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
ourSong.release();
finish();
}
}
Frenchsilk.java
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;
public class FrenchSilk extends Activity {
/** Called when the activity is first created. */
AnimationDrawable mainanimation;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.frenchsilk);
ImageView mainimage = (ImageView) findViewById(R.id.MainAnim);
mainimage.setBackgroundResource(R.anim.mainanim);
mainanimation = (AnimationDrawable) mainimage.getBackground();
// mainanimation.start();
}
public void onWindowFocusChanged (boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
// AnimationDrawable frameAnimation = (AnimationDrawable) mainimage.getBackground();
// if(hasFocus) {
mainanimation.start();
// } else {
// mainanimation.stop();
// }
}
}
I commented a few things out with * (and // within the actual codeing process) becuase it was messing up the code line spacing. I was thinking that under the sleep(4800); line that a class or something might go there telling the animation to start or something.
Ok so i figured it out myself. Just had to put the code into the respected places and the onWindow changed at the bottom of the main java file.