I am facing the problem while retrieving the contacts from the contact book in Android 8.0 Oreo java.lang.IllegalStateException: Only fullscreen opaque activities can reques
it seems when target sdk is pie (api level 28.0) and windowIsTranslucent is true
<item name="android:windowIsTranslucent">true</item>
and you try to access orientation. problem comes with android oreo 8.0 (api level 26) there are two ways to solve this
if you are setting orientation in manifest like this
android:screenOrientation="portrait"
or in activity class like this
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
remove form both places.
and observed when u set windowIsTranslucent to true, it takes orientation from parent activity.
Just Set Orientation of activity in Manifiest.xml
android:screenOrientation="unspecified"
OR for restricted to Portrait Orientation
You can also use in Activity, In onCreate
method call before super.onCreate(...)
e.g.
@Override
protected void onCreate(Bundle savedInstanceState) {
setOrientation(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.your_xml_layout);
//...
//...
}
// Method
public static void setOrientation(Activity context) {
if (android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.O)
context.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
else
context.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
The problem seems to be happening when your target sdk is 28. So after trying out many options finally this worked.
<activity
android:name=".activities.FilterActivity"
android:theme="@style/Transparent"
android:windowSoftInputMode="stateHidden|adjustResize" />
style:-
<style name="Transparent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
Note:parent="Theme.AppCompat.Light.NoActionBar" is needed for api 28. Previously had something else at api 26. Was working great but started to give problem at 28.
Hope it helps someone out here.
EDIT: For some only by setting <item name="android:windowIsTranslucent">false</item> and <item name="android:windowIsFloating">false</item>
worked.May be depends upon the way you implement the solution works.In my case it worked by setting them to true.
Just remove this line android:screenOrientation="portrait"
of activity in Manifiest.xml
That activity will get orientation from it's previous activity so no need to apply orientation which has <item name="android:windowIsTranslucent">true</item>
.
Please check the style of your Activity and make sure if you are not using any Translucent related things, change the style to alternate. So that we can fix this problem.
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
If you use a fullscreen transparent activity, there is no need to specify the orientation lock on the activity. It will take the configuration settings of the parent activity. So if the parent activity has in the manifest:
android:screenOrientation="portrait"
your translucent activity will have the same orientation lock: portrait.