I'm programming an application with an initial logo activity. It has to be displayed for 1 second and then launch the main activity using a custom transition.
The problem is that the logo activity is displayed for 1 second, but the animation is quite always the standard and rarely displays the custom animation I made.
This is the code in logoActivity.class :
Thread thread;
i = new Intent(this, mainActivity.class);
thread= new Thread(){
@Override
public void run(){
try {
synchronized(this){
Thread.sleep(1000);
}
}
catch(InterruptedException ex){
Log.d("Event Loop", "Exception: " + ex.toString());
}
startActivity(i);
overridePendingTransition(R.anim.anim_out, R.anim.anim_in);
finish();
}
};
this is the code in anim_out.xml :
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:fromXDelta="0%p"
android:toXDelta="100%p"></translate>
and this is the code in anim_in.xml:
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:fromXDelta="-100%p"
android:toXDelta="0%p"></translate>
I use those animations to set the custom transition from mainActivity and secondActivity too, and it works perfectly.
Please, help me solving this problem!
Try using a countDownTimer which is better than this approach.
CountDownTimer timer = new CountDownTimer(1000,1000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
timer.cancel();
timer = null;
startActivity(i);
overridePendingTransition(R.anim.anim_out, R.anim.anim_in);
finish();
}
};
timer.start();
I believe your intention is to display a kind of SplashScreen between activities with a custom animation instead of a single image.
Here`s an excellent tutorial on how to do this
http://www.codeproject.com/Articles/113831/An-Advanced-Splash-Screen-for-Android-App
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.