I am doing a minimal prototype of animating view from one activity (MainActivity) to another (NextActivity) via container transform.
It works however when I exit the app, the transformed view stays for a while on launcher, which is unintended.
I guess it is probably an SDK bug, but do let me know if there is any workaround available, or did I missed out anything.
Device: OnePlus 5T
MainActivity#onCreate
window.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS)
setExitSharedElementCallback(MaterialContainerTransformSharedElementCallback())
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val icon: View = findViewById(R.id.icon)
icon.postDelayed({
val intent = Intent(this, NextActivity::class.java)
val options = ActivityOptions.makeSceneTransitionAnimation(
this,
icon,
"splash"
)
startActivity(intent, options.toBundle())
finish()
}, 300)
NextActivity#onCreate
window.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS)
setEnterSharedElementCallback(MaterialContainerTransformSharedElementCallback())
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_next)
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/icon"
android:layout_width="500dp"
android:layout_height="500dp"
android:layout_gravity="start|bottom"
android:background="@color/teal_200"
android:transitionName="splash" />
activity_next.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/icon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="end|top"
android:background="@color/purple_200"
android:transitionName="splash" />
</FrameLayout>
