I am currently working on an application that is supposed to have a transition from the splash screen to a main menu screen. I have done the coding but it doesnt seem to do that. Can anyone please spot out what is wrong with the code below?
Splash screen Activity:
public class MainActivity extends Activity {
public static final String GAME_PREFERENCES = "GamePrefs";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
// fade in animation
TextView logo1 = (TextView)findViewById(R.id.TextViewTopTitle);
Animation fade1 = AnimationUtils.loadAnimation(this, R.anim.fade_in);
logo1.startAnimation(fade1);
// custom animation
Animation spining = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
LayoutAnimationController controller = new LayoutAnimationController(spining);
TableLayout table = (TableLayout)findViewById(R.id.TableLayout01);
for(int i=0; i < table.getChildCount(); i++)
{
TableRow row = (TableRow) table.getChildAt(i);
row.setLayoutAnimation(controller);
}
startAnimations();
// saving game preferences
SharedPreferences settings = getSharedPreferences(GAME_PREFERENCES, MODE_PRIVATE);
SharedPreferences.Editor prefEditor = settings.edit();
prefEditor.putString("UserName", "JaneDoe");
prefEditor.putInt("UserAge", 22);
prefEditor.commit();
}
private void startAnimations() {
// Transition from Splash screen to Main Menu screen
Animation fade2 = AnimationUtils.loadAnimation(this, R.anim.fade_in2);
fade2.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation animation)
{
startActivity(new Intent(MainActivity.this,QuizMenuActivity.class));
MainActivity.this.finish();
}
public void onAnimationStart(Animation animation)
{
//Nothing
}
public void onAnimationRepeat(Animation animation)
{
//Nothing
}
});
}
Main Menu Activity:
public class QuizMenuActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
}
}
My layouts are done already. Any suggestions on what is wrong here?
Maybe the AnimationListener is never triggered? If you just want the Splash screen to display then leave.. how about just trying adding the following to your Splash activity’s onCreate:
It sleeps for 5 seconds then goes to the MainMenu.
Edit
I think your AnimationListener is never being invoked, so try adding
fade2.startNow()here:For more information on how to use
Animation.startNow()orAnimation.start():animation.start() or animation.startNow() does not start the animation immediately