Your own custom transitions within an Android app

Below is a function that takes you to another activity (namely, LocationsActivity). Instead of using the usual startActivity(), we call startActivity through this function:

public void locationsClick(View v) throws
JSONException, IOException {
Utils.forwardToActivity(this, new Intent
(this, LocationsActivity.class));
}

And in that function, we can override the transition, to our custom ones R.anim.move_in_right, R.anim.move_out_left.

/**
* go forward to given activity. Makes the new activity
* scroll in from * the right, hence the 'forward'.
**/

public static void forwardToActivity
(Activity currentActivity, Intent intent) {
currentActivity.startActivity(intent);
currentActivity.overridePendingTransition
(R.anim.move_in_right, R.anim.move_out_left);
}
Advertisements