How to add animation to completion of activity ()

I use overridePendingTransition for when my activity is created, and it works great. I can see that attenuation works fine, but when I try to animate the finish in my activity, it still defaults to right to left.

At first I tried to define the animation out when I start the action as follows:

Intent myIntent = new Intent(a, SkdyAlert.class); myIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); a.startActivity(myIntent); if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONUT) { AnimationHelper.overridePendingTransition(a, R.anim.fadein, R.anim.fadeout); } 

Then I tried to do this when I finish the work as well

 okBtn.setOnClickListener(new OnClickListener() { public void onClick(View v) { finish(); if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONUT) { AnimationHelper.overridePendingTransition(activity, 0, R.anim.fadeout); } } }); 

But none of these approaches will prevent a right-to-left slide to animate the output. Any ideas on what I'm doing wrong?

+65
android android-activity animation
Dec 02 2018-10-12T00:
source share
9 answers

I override the pending transition immediately after calling finish ();

In my case, I did this to avoid transitions.

 finish(); Details.this.overridePendingTransition(R.anim.nothing,R.anim.nothing); 

The order is important :)

+185
Jan 05 '12 at 11:40
source share
β€” -

I fixed this problem using this approach:

to open with animation:

  Intent newUser = new Intent(getBaseContext(), NewUserActivity.class); startActivity(newUser); overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left); 

To close the animation:

 @Override public boolean onOptionsItemSelected(MenuItem item) { onBackPressed(); return super.onOptionsItemSelected(item); } @Override public void onBackPressed() { super.onBackPressed(); overridePendingTransition(R.anim.slide_out_right,R.anim.slide_in_right); } 
+14
Jun 10 '14 at 12:35
source share
 finish(); overridePendingTransition(0, 0); 
+12
Mar 13 '13 at 22:59
source share

I would suggest using the isFinishing () method to set the animation in onPause instead of calling finish ()

 @Override protected void onPause() { super.onPause(); if (isFinishing()){ overridePendingTransition(R.anim.activity_slide_in, R.anim.activity_slide_out); } } 
+12
May 20 '15 at 10:56
source share

Look at this through the topic. You can define input animation output for actions or the entire application

+11
Dec 02 2018-10-12T00:
source share

This question has already been answered, but the most effective way to put animation when exiting an action is to override the "finish ()" method of the related activity:

 @Override public void finish() { super.finish(); overridePendingTransition(R.anim.hold, R.anim.slide_out_bottom); } 
+10
Aug 05 '15 at 13:09 on
source share

Following @schwiz's answer, this is an animation override for the built-in Dialog theme, where I defined local animations slide_up and slide_down. My activity defines the MyDialog theme to enter and exit them.

 <style name="Animation.MyDialog" parent="android:Animation.Dialog"> <item name="android:windowEnterAnimation">@anim/slide_up</item> <item name="android:windowExitAnimation">@anim/slide_down</item> </style> <style name="Theme.MyDialog" parent="android:Theme.Dialog"> <item name="android:windowAnimationStyle">@style/Animation.MyDialog</item> </style> 

+6
Oct 26
source share

Use startActivityForResult to start your child activity and in onActivityResult () of your parent action:

  @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode==REQUEST_YOUR_ACTIVITY) { overridePendingTransition(R.anim.parent_appearing_anim, R.anim.child_dissmissing_anim); } super.onActivityResult(requestCode, resultCode, arg2); } 
+5
Sep 25 '13 at 11:31 on
source share
 if (getEnterAnimation() > -1 && getExitAnimation() > -1) { overridePendingTransition(getEnterAnimation(), getExitAnimation()); } 

where these methods return animations from R.anim.YOUR_ANIMATION_XML

add this code to your onCreate () before

 setContentView() 

and in your onPause () before

 super.onPause() 

I tried adding this code before / inside these methods, but the exit animation never worked

 startActivity() finish() onBackPressed() 
0
Oct 05 '15 at 11:40
source share



All Articles