0

The

android:configChanges="screenSize|orientation|keyboardHidden">

tag has no effect. My activity always is destroyed when the device is rotated. I do not know why this is. I have added every possible flag to the above and it still has no effect. Another relevant (?) fact: this activity contains an OpenCv JavaCameraView (camera 1 under the hood).

Here is the xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.mycompany.myname.mycamera">

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="false"
    android:theme="@style/AppTheme">

    <activity
        android:name=".activities.CaptureActivity"
        android:configChanges="screenSize|orientation|keyboardHidden">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>

Why might this tag not be having any effect?

e: I should specify: I want to prevent my activity from being destroyed on rotation, but I do want to know when a rotation occurs and what the current orientation is.

poppy
  • 247
  • 2
  • 15
  • what is your requirement, Do you want to stop orientation of activity.. – jessica Jan 22 '18 at 04:17
  • I want to prevent my activity from being destroyed on rotation, but I do want to know when a rotation occurs and what the current orientation is. – poppy Jan 22 '18 at 04:20
  • read this, https://developer.android.com/guide/topics/resources/runtime-changes.html – jessica Jan 22 '18 at 04:29
  • How are you determining that the activity is being destroyed? – clownba0t Jan 22 '18 at 05:30
  • I just checked - the activity isn't actually being destroyed! However, my activity's layout completely changes on orientation. – poppy Jan 23 '18 at 02:06

1 Answers1

0

This should work:

android:configChanges="orientation|screenSize"

For detecting orientation change:

@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();
    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    }
}
Rahul Singh Chandrabhan
  • 2,531
  • 5
  • 22
  • 33