Jignesh Ansodariya Jignesh Ansodariya - 1 month ago 21
Android Question

How to apply slide animation between two activities in Android?

I want slide effect left to right when I change the Activity and for that I am using following code
but not getting any result. please correct me.
Thanks

in java both file

super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
setContentView(R.layout.main);


two files in res/anim directory

fadein.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="5000"
android:fromAlpha="0.0"
android:interpolator="@android:anim/slide_out_right"
android:toAlpha="1.0" >
</alpha>


fadeout.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="5000"
android:fromAlpha="0.0"
android:interpolator="@android:anim/slide_in_left"
android:toAlpha="1.0" >
</alpha>

MAC MAC
Answer
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splashscreen);

         new Handler().postDelayed(new Runnable() {
             public void run() {

                     /* Create an intent that will start the main activity. */
                     Intent mainIntent = new Intent(SplashScreen.this,
                             ConnectedActivity.class);
                     mainIntent.putExtra("id", "1");

                     //SplashScreen.this.startActivity(mainIntent);
                     startActivity(mainIntent);
                     /* Finish splash activity so user cant go back to it. */
                     SplashScreen.this.finish();

                     /* Apply our splash exit (fade out) and main
                        entry (fade in) animation transitions. */
                     overridePendingTransition(R.anim.mainfadein,R.anim.splashfadeout);
             }
     }, SPLASH_DISPLAY_TIME);   
    }