I created an activity ( activity no. 1 ) with 2 Views, one button and one textView these two views are shared to another activity ( activity no. 2 )
I use the following code to start from activity1 to activity2 with the shared elements:
Pair textView = new Pair<>(view1, ViewCompat.getTransitionName(view1)); Pair button = new Pair<>(view2, ViewCompat.getTransitionName(view2)); ActivityOptionsCompat transitionActivityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation( Activity1.this, textView, button); Intent intent = new Intent(Activity1.this, Activity2.class); ActivityCompat.startActivity(Activity1.this, intent, transitionActivityOptions.toBundle()); When I press the back button the views are animated back to Activity1.The animation stop from work after I Override the back buton with the following code:
@Override public void onBackPressed(){ Intent intent = new Intent(Detailed.this, Main.class); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); intent.putExtra("morph", morphButton.getMorph()); startActivity(intent); finish(); } The startActivity method cancel the animation.
I am trying to achieve this because I want to pass back to Activity1 some variables. Is there a way how can I maintain the animation with startActivity method ?