overridePendingTransition in Android SDK doesn't work
overridePendingTransition is a method of Activity. Just as you have done for the call to finish(), try using
FDSplashActivity.this.overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
Daniel Jonsson
Working as a full stack developer. Studied software engineering at Chalmers University of Technology in Sweden. My LinkedIn profile: https://www.linkedin.com/in/dnljnssn
Updated on June 05, 2022Comments
-
Daniel Jonsson almost 2 years
I'm trying to get change the transition between two activities in an Android application. I found that overridePendingTransition would do the job, but it doesn't seem to work for me. This is the code I'm working with:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); ImageView logo = (ImageView) findViewById(R.id.ImageView01); Animation fade = AnimationUtils.loadAnimation(this, R.anim.fade_in); fade.setAnimationListener(new AnimationListener() { @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animation animation) { startActivity(new Intent(FDSplashActivity.this, FDGameActivity.class)); FDSplashActivity.this.finish(); overridePendingTransition(R.anim.fade_in, R.anim.fade_out); } }); logo.startAnimation(fade); }
It's supposed to show the splash screen, fade in a logo and then switch to another activity. That works, but not the line overridePendingTransition(R.anim.fade_in, R.anim.fade_out);. When I'm hovering it in Eclipse it just says: "The method overridePendingTransition(int, int) is undefined for the type new Animation.AnimationListener(){}"
Please help me.
-
Daniel Jonsson over 13 yearsAh, right, thanks. But I replaced the line with yours and I'm still getting a red line under the word overridePendingTransition. What am I doing wrong? Am I using the wrong SDK version?
-
Daniel Jonsson over 13 yearsI was. Eclipse had automatically picked Android 1.6 as the Project Build Target. But after changing to 2.1 instead, it now works great. Thanks man!
-
Rahmathullah M over 9 yearsinside a fragment, use it like
getActivity().overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);