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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s