How to disable supportFinishAfterTransition when backing out from an activity - android

I have an activity I animate to with a transition animation, like this:
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, view, transitionStr);
ActivityCompat.startActivity(activity, intent, options.toBundle());
However, when I go back, I don't want the animation to run in inverse. Is that possible? I'm using AppCompatActivity from appcompat-v7:23.1.1.

If you never want to have that transition back to the parent activity, use
finish();
You can wrap it around a condition if you sometimes want to the transition on the way back to the parent activity. An example use case would be to disable the transition when an interstitial ad was displayed:
if (interstitialAdWasDisplayed) {
finish();
} else {
finishAfterTransition();
}

A possible duplicate of Overriding Transition
finish();
Details.this.overridePendingTransition(R.anim.nothing,R.anim.nothing);
With this piece of code, you can override the finish animation of the current activity.

According to the answers to this question you can't run an animation in inverse. Instead I would create another transition which is basically the inverse of the transition you use when you start the activity and add it to the Activity like this (R.anim.inverseTransition is the Transition you created):
finish();
Details.this.overridePendingTransition(R.anim.inverseTransition,R.anim.inverseTransition);
(see this answer for more information)

Related

ExitTransition doesn't work if not set up in onCreate

I would like to set up my exit transition with specific target views (addTarget) which I only know after the user has clicked an item, therefore I instantiate it only before starting the new activity.
However, this way the exit transition is not applied at all, event without the addTarget calls. When I navigate back and start the activity with transition again, it's working well.
private fun onItemClick(id: Long) {
window.exitTransition = Slide(Gravity.LEFT)
val activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(this, ..).toBundle()
val intent = Intent(this, SettingsActivity::class.java)
ActivityCompat.startActivity(this, intent, activityOptions)
}
Can I make the transition work also for the first time?
I think it is the correct behavior but tough to know without a code example.
The recommended way to change the transitions is
// inside your activity (if you did not enable transitions in your theme)
with(window) {
requestFeature(Window.FEATURE_CONTENT_TRANSITIONS)
// set an exit transition
exitTransition = Explode()
}
as discussed here: https://developer.android.com/training/transitions/start-activity
If you are having this problem in the AndroidStudio emulator specifically, you might want to update AndroidStudio. I had a problem in an older version where a button's behavior was always different the fist time I refreshed the app.
The exit transition must be set before calling ActivityOptions.makeSceneTransitionAnimation to make it work.
I figured it out by looking at these classes:
ActivityTransitionCoordinator
ExitTransitionCoordinator

Transition Animation From Fragment To Activity Android

In my application, I want to transit from Fragment to Activity.
For this purpose I am using following code for Animation,
Bundle bndlanimation =ActivityOptions.makeCustomAnimation(getActivity(), R.anim.slideinleft,R.anim.slideinright).toBundle();
startActivity(intentonboard,bndlanimation);
This works fine.
But What I want to do is that, I am moving from Fragment To Activity.
So I just want to apply the exit animation for Fragment only. Next Activity should be added behind the scene without animation.
So What Should I write in place of enter animation ?
I tried with 0 instead of R.anim.slideinright. But It effects on Exit animation.
Thanks
if you in fragment Layout and wanna to get intent to same activity you must use this...
Intent intent = new Intent(getActivity(),MainActivty.class);
startActivity(intent);
getActivity().overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
getActivity().overridePendingTransition(R.animator.slide_in_from_left, R.animator.slide_in_from_right);
Use getActivity() After startActivity(intent);
May this help you.

Catch the end of Return Activity Transition

From Activity A to B , I set enter and return transitions.
I want to put a fadein animation after the return transition ( B to A after a back).
Originally , I thought that in Activity's onStart method will a good place.
It turns out I don't see the fadein animation so I suppose the ending of the Return Transition happens after onStart()
I checked with SharedElementCallback but it doesn't tell when the transition ends.
How to catch the moment when the Return Transition ends ?
For Activity you'll need to call overridePendingTransition() in Activity A after calling startActivity() and provide your own animations. You can also override onEnterAnimationComplete() in Activity A so you know when it has been animated on to the screen.
For Fragments, you can do this by adding your own custom animations for the transitions using setCustomAnimations() on the transaction. These will override the default animations for your Fragment transitions.

Animate views before activity finished

I use view animations in a predrawlistener to animate the activity start.
Exist a similar listener to animate my views before my activity is finished?
I know the overridependingtransition method for animations in xml but i want to use ViewPropertyAnimations in a programmatically way for specific views.
I suggest you to override finish() method, then add your animation there:
#Override
public void finish (){
// do your animation
super.finish();
}
You can call YourActivity.finsih(); when you want to finish your activity from code.

Overriding pending transition with animation object instead of resource id

Is there any way to override the pending transition by passing it actual Animation object instead of an ID to an animation resource?
From
startActivity(intent);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
To
startActivity(intent);
overridePendingTransition(new MyFadeInAnimation(), new MyFadeOutAnimation());
If not, is there a way for me to manually register an animation resource (and attain an ID) programatically?
I really do not want to define the activity transition animations as XML for other reasons.
So one way to do this is to use Fragments. Set overridePendingTransition(0,0); for the Activity. and then in the Fragment, override onCreateAnimator() or if using the old animations, use android.support.v4.app.Fragment and override onCreateAnimation().

Categories

Resources