Need to temporarily lock the screen orientation on your app? When calling setRequestedOrientation() on your activity, it will no longer allow the orientation to change even when the phone is rotated. So check what the current orientation of the screen is and set it to the same orientation with setRequestedOrientation()

public static void lockCurrentScreenOrientation(Activity a) {

	if(a.getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
		a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	} else {
		a.setRequestedOrientation(a.getRequestedOrientation());
	}
}

To unlock it again, pass ActivityInfo.SCREEN_ORIENTATION_USER:

public static void unlockScreenOrientation(Activity a) {
	a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
}