Reputation: 2539
Problem
I want to achieve shared element transition between Activity A and B, and between Activity B and C.
I did everything based on the android transition documentation.
There is no problem between:
A => B => back to A
A => B and B => C => back to B
But if I do:
The last step will not have any shared element transition (actually not only shared element transition, even there is only fading it could be lost).
I have been looking for solutions everywhere, but it seems everybody only needs A => B (and B => A) shared element transition but doesn't care any more transitions from B => C and back to A.
Example
See an example I created based on android's animation samples, where Activity A = MainActivity, B = DetailActivity, C = DetailDetailActivity. Clicking the button on Activity B will navigate to Activity C.
Upvotes: 5
Views: 391
Reputation: 11
Because while executing C => B, it will re-construct a new EnterTransitionCoordinator for B, replacing the old one contains the correct mPendingExitNames
which it is important to indicate views need to be transitioned between A and B.
public boolean startExitBackTransition(final Activity activity) {
ArrayList<String> pendingExitNames = getPendingExitNames(); // here
if (pendingExitNames == null || mCalledExitCoordinator != null) {
return false;
} else {
// ...
}
}
The solution seems to be a little bit tricky. You can refer to ThreeActivityTransitionDemo and pay attention to the SharedElementUtils
.
Upvotes: 1
Reputation: 5093
Add this to Activity B
@Override
protected void onStop() {
if(Build.VERSION.SDK_INT == Build.VERSION_CODES.Q && !isFinishing()){
new Instrumentation().callActivityOnSaveInstanceState(this, new Bundle());
}
super.onStop();
}
Upvotes: 0