Android’s overridePendingTransition and singleInst

2019-02-18 00:20发布

问题:

I am stuck on an issue with overridePendingTransition not working after changing an activity’s launchMode to ‘singleInstance’. I’d love to hear your inputs on it

I am working on an app to navigate through a deck of cards. To keep things simple, let’s assume the App contains two activities card_deck and card. Tapping anywhere on the card_deck activity opens a card activity. You could then swipe left or right on the card activity to open the next/previous card from the deck. I have a neat enter and exit animation that occurs on swiping through card.

Here is how the android activity stack would look

As you have guessed by now, there are too many activities of type card.

I changed the launchMode of card activity from standard to singleInstace (I had yet another adMob related reason to go the singleInstance route). Now when I call the following code snippet, the animation no longer occurs.

from Card.class

Intent intent = new Intent(activity, Card.class);
activity.startActivity(intent);
activity.overridePendingTransition(enterAnim, exitAnim);

I think the animation is suppressed as there will only be one activity of type card and it's onCreate will not be called (‘cos of making it single instance). I have also tried calling the overridePendingTransition() on onNewIntent()/onResume() but it did not help.

In a nutshell, how could I display enter & exit animation when calling startActivity(activity, A.class) from A.class when ‘A’ has a launchMode of singleTop/singleInstance