In your manifest file, give the following android:configChanges="keyboardHidden|orientation" camera view activity properties android:configChanges="keyboardHidden|orientation" for more details this
<activity android:name=".Your_Activity_Name" android:configChanges="keyboardHidden|orientation" android:label="@string/app_name" > <intent-filter> </intent-filter> </activity>
And in your activity class, redefine onConfigurationChanged and make the orientation screen (as necessary, landscape or portrait) (as necessary) as follows:
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); // Checks the orientation of the screen if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show(); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); //Your code to do the other things in landscape mode... } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){ Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show(); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //Your code to do the other things in portrait mode... } }
I hope this helps you get rid of your problem.
source share