I’ve created a “back to home” type button in Android by using the code:
Intent i=new Intent(this, Home.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
However, when android transitions to the Home activity, it slides the activity in from right-to-left, giving the user the impression that a new activity was launched. The user then expects that when pressing “back”, the previous activity would come up, which is obviously not the case.
How can I tell android to slide backwards (i.e. from left-to-right) so that the transition indeed gives the appearance of closing the previous activities?
You can override the animation by calling
overridePendingTransition()afterstartActivity().Look at this example from google.
Take a look at how to create an animation resource too.