I am trying to get a material transition to work from a FAB in Activity A to Activity B and back. Its currently working but with a slight issue. When I click on a FAB it expands to the Activity B using material transition with no issues. But when I transition back from Activity B to Activity A, Activity B duplicates and is still present for a second during the transition and it takes a second for it to disappear fully.
Here is the guide I followed:
https://material.io/develop/android/theming/motion
Specifically under the section, "Container transform examples" and under the subsection "Transition between Activities".
Here is what the issue I am facing looks like. Hopefully these images give a clear idea. In these images I am transitioning from Activity B to Activity A. This is where the problem is
The back button is pressed and Activity B transforms back into the FAB in Activity A
Now the FAB from Activity A is visible again but Activity B is still visible
Finally Activity B disappears and Activity A is visible again.
As you can see once the back button is pressed Activity A should appear immediately but it still shows Activity B for a second.
Here is what I have in my code which is basically just following the guide:
In Activity A in the onCreate method:
setExitSharedElementCallback(new MaterialContainerTransformSharedElementCallback());
getWindow().setSharedElementsUseOverlay(false);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
And in the onClick of the FAB in Activity A:
FloatingActionButton newTaskButton = (FloatingActionButton) findViewById(R.id.newTaskButton);
newTaskButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(MainActivity.this, newTaskButton, "shared_container");
Intent intent = new Intent(MainActivity.this, CreateNewTask.class);
startActivityForResult(intent, 1, options.toBundle());
}
});
And in the onCreate method of Activity B:
findViewById(android.R.id.content).setTransitionName("shared_container");
setEnterSharedElementCallback(new MaterialContainerTransformSharedElementCallback());
MaterialContainerTransform transform = new MaterialContainerTransform();
transform.addTarget(android.R.id.content);
transform.setAllContainerColors(MaterialColors.getColor(findViewById(android.R.id.content), R.attr.colorSurface));
transform.setFitMode(MaterialContainerTransform.FIT_MODE_AUTO);
transform.setDuration(550L);
transform.setPathMotion(new MaterialArcMotion());
transform.setInterpolator(new FastOutSlowInInterpolator());
transform.setScrimColor(Color.parseColor("#4AED93"));
getWindow().setSharedElementEnterTransition(transform);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_new_task);
I have enabled window transitions for the theme
<!-- enable window content transitions -->
<item name="android:windowActivityTransitions">true</item>
I thought this might be an issue with the scrim color or container color but these dont affect this particular issue. Can you guys advise?