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

1.1k Views Asked by At

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()?

1

There are 1 best solutions below

1
Mohammad Rbabah On

you can user this (Kotlin code)

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


}