Use overridePendingTransition in conjuction with recreate(). Can it be done?
Asked Answered
C

1

8

I've been using Android's overridePendingTransition method to animate my activity page transitions with great success. Example shown

startActivity(new Intent(GetTagActivity.this, MainActivity.class));
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

I have a situation that I need to "refresh" a page and desire a fade transition. Without going into the details, I can't use the StartActivity(...)method to call the refresh (which would allow for the animation call).

Using recreate()works perfect to "refresh" the page, however I haven't been able to add the transition animation. This hasn't worked.

recreate();
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

nor this

recreate().overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

Can fade animation (or any activity transition) be used with recreate()?

Cienfuegos answered 10/2, 2017 at 23:12 Comment(3)
What about finish() followed by startActivity()?Highminded
Any updates on this? I stumbled across same requirement.Cigarette
No update specifically to the question, however since this post, I have learned how to use activity flags in conjunction with onNewIntent that has allowed me to mimic recreate() with a startActivity() call and use animation. Doesn't work for every situation but is something to look into.Cienfuegos
B
-3

you can user this (Kotlin code)

  override fun recreate() {
    finish()
    startActivity(Intent(this,this.javaClass))
    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);


}
Bowers answered 20/9, 2019 at 13:4 Comment(1)
my question specifically stated not to use the startActivity() method.Cienfuegos

© 2022 - 2024 — McMap. All rights reserved.