Is there a possibility to use shared element transition between two different apps?
Yes, shared elements will work between different applications. You have to agree on a common name to share between the two applications. Normally this is done with the transitionName as @AlexLockwood suggests, but the views don't have to carry the same name. It just happens that if you do, you get a lot of help for free.
There is an important aspect of sharing elements between applications -- they must be in the same task. The Activity Options will be rejected if they aren't in the same task.
If you want to use different transitionNames in the layout, you just do this:
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(
this, view, "remoteName");
startActivity(intent, options.toBundle());
Now, if the remote application used "remoteName" for the transitionName in its layout file, it doesn't have to do anything special. However, if it uses a different name, it must map the name to a view:
setEnterSharedElementCallback(new SharedElementCallback() {
@Override
public void onMapSharedElements(List<String> names,
Map<String, View> sharedElements) {
// You may want to validate that names contains "remoteName"
// if this can be instantiated with different shared elements
sharedElements.put("remoteName", findViewById(R.id.mySharedElement));
}
});
This functionality is important when you share to something that has a list of views, any of which may be shared. For example, a list of contacts will have all contact images with different transitionNames. Going from a single contact to that list of contacts, you need to map the single shared contact to one of the contacts in the list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With