Android: How to stick to the same orientation the activity started with


I know how to lock an activity in a specific orientation (in AndroidManifest.xml):


I know how to lock to a specific orientation programmatically:


But, how do I lock the activity to the orientation in which started at? e.g., if it started portrait, it should stick to that.


Use getResources().getConfiguration().orientation when your app starts, then programmatically set the orientation like you do above. The method will return either ORIENTATION_LANDSCAPE or ORIENTATION_PORTRAIT