Android examples for android.app:Activity
lock Activity Orientation
import android.app.Activity; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.net.Uri; import android.os.Bundle; public class Main{ public static int lockActivityOrientation(Activity activity) { int oldOrientation = activity.getRequestedOrientation(); int currentOrientation = activity.getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } else {//from ww w. j av a2 s. c om activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } return oldOrientation; } }