- Saved searches
- Use saved searches to filter your results more quickly
- Only fullscreen opaque activities can request orientation #63
- Only fullscreen opaque activities can request orientation #63
- Comments
- java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
- Solution 2
- Solution 3
- Solution 4
- Solution 5
- Related videos on Youtube
- Shubham Sejpal
- Comments
- About the crash
- cause
- Is it a bug? Is it a specification?
- Resolution
- Supports screen rotation
- Behind orientation
- Lowering targetSdkVersion for a moment
- Summary
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only fullscreen opaque activities can request orientation #63
Only fullscreen opaque activities can request orientation #63
Comments
version: tedpermission-rx2:2.0.3
phone: emulator Nexus 5X 26, 27
java.lang.RuntimeException: Unable to start activity ComponentInfo: java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) Caused by: java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation at android.app.Activity.onCreate(Activity.java:987) at android.support.v4.app.SupportActivity.onCreate(SupportActivity.java:66) at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:297) at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:84) at com.gun0912.tedpermission.TedPermissionActivity.onCreate(TedPermissionActivity.java:64) at android.app.Activity.performCreate(Activity.java:7000) at android.app.Activity.performCreate(Activity.java:6991) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
The text was updated successfully, but these errors were encountered:
java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
The problem seems to be happening when your target sdk is 28. So after trying out many options finally this worked.
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
Solution 2
In android Oreo (API 26) you can not change orientation for Activity that have below line(s) in style
You have several way to solving this :
1) You can simply remove above line(s) (or turn it to false) and your app works fine.
2) Or you can first remove below line from manifest for that activity
android:screenOrientation="portrait"
Then you must add this line to your activity (in onCreate())
//android O fix bug orientation if (android.os.Build.VERSION.SDK_INT != Build.VERSION_CODES.O)
3) You can create new styles.xml in values-v26 folder and add this to your style.xml . (Thanks to AbdelHady comment)
Solution 3
In Android O and later this error happens when you set
android:screenOrientation="portrait"
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Solution 4
Google throws this exception on Activity’s onCreate method after v27, their meaning is : if an Activity is translucent or floating, its orientation should be relied on parent(background) Activity, can’t make decision on itself.
Even if you remove android:screenOrientation=»portrait» from the floating or translucent Activity but fix orientation on its parent(background) Activity, it is still fixed by the parent, I have tested already.
One special situation : if you make translucent on a launcher Activity, it has’t parent(background), so always rotate with device. Want to fix it, you have to take another way to replace
Solution 5
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:
your translucent activity will have the same orientation lock: portrait.
Related videos on Youtube
Shubham Sejpal
I am an ambitious Android Developer at Globocom Infotech Pvt. Ltd. , Worked on many Android Apps. I am a hard working android geek and love learning new techniques in android . Always looking for new hard challenges , because nothing good comes easily and an active brain is more powerful, creative and age less! «Our life is a beautiful experience full of challenges that we need to overcome with creativity and imagination. Be crazy enough to think outside your own limitations and do more than other ones could even dream.» Mr. Possible
Comments
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 request orientation I am trying to get the contact in my activity from the phone contact book and it works perfect for Lollipop, Marshmallow, Nougat, etc but it will gives me the error for Oreo like this please help me. My code is here below. Demo Code :-
private void loadContacts() < contactAsync = new ContactLoaderAsync(); contactAsync.execute(); >private class ContactLoaderAsync extends AsyncTask < private Cursor numCursor; @Override protected void onPreExecute() < super.onPreExecute(); Uri numContacts = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; String[] numProjection = new String[]; if (android.os.Build.VERSION.SDK_INT < 11) < numCursor = InviteByContactActivity.this.managedQuery(numContacts, numProjection, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " COLLATE NOCASE ASC"); >else < CursorLoader cursorLoader = new CursorLoader(InviteByContactActivity.this, numContacts, numProjection, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " COLLATE NOCASE ASC"); numCursor = cursorLoader.loadInBackground(); >> @Override protected Void doInBackground(Void. params) < if (numCursor.moveToFirst()) < try < final int contactIdIndex = numCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID); final int displayNameIndex = numCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME); final int numberIndex = numCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); final int typeIndex = numCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE); String displayName, number, type; do < displayName = numCursor.getString(displayNameIndex); number = numCursor.getString(numberIndex); type = getContactTypeString(numCursor.getString(typeIndex), true); final ContactModel contact = new ContactModel(displayName, type, number); phoneNumber = number.replaceAll(" ", "").replaceAll("\\(", "").replaceAll("\\)", "").replaceAll("-", ""); if (phoneNumber != null || displayName != null) < contacts.add(phoneNumber); contactsName.add(displayName); contactsChecked.add(false); filterdNames.add(phoneNumber); filterdContactNames.add(displayName); filterdCheckedNames.add(false); >> while (numCursor.moveToNext()); > finally < numCursor.close(); >> Collections.sort(contacts, new Comparator() < @Override public int compare(String lhs, String rhs) < return lhs.compareToIgnoreCase(rhs); >>); InviteByContactActivity.this.runOnUiThread(new Runnable() < @Override public void run() < mContactAdapter.notifyDataSetChanged(); >>); return null; > > private String getContactTypeString(String typeNum, boolean isPhone) < String type = PHONE_TYPES.get(typeNum); if (type == null) return "other"; return type; >static HashMap PHONE_TYPES = new HashMap(); static < PHONE_TYPES.put(ContactsContract.CommonDataKinds.Phone.TYPE_HOME + "", "home"); PHONE_TYPES.put(ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE + "", "mobile"); PHONE_TYPES.put(ContactsContract.CommonDataKinds.Phone.TYPE_WORK + "", "work"); >>
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example, PID: 6573 java.lang.RuntimeException: Unable to start activity ComponentInfo: java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation Caused by: java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
Its a bug from google side. Should be fixed in future updates. setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); will restrict your app from going into landscape. Make sure you use this in on create of all your activities.
This solution works, but it messes up my splashScreenTheme. Shame on Google for frequent sloppy roll-outs.
About the crash
When the four conditions are met, the following crash occurs.
java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
It doesn’t seem to happen on Android 8.1 or later. That is, if you set the targetSdkVersion to 27, it will only crash on Android 8.0 (=API level 26).
version | API Level |
---|---|
Android 8.0 | 26 |
Android 8.1 | 27 |
If you write it in code, it looks like this:
Have targetSdkVersion 27 or higher
android defaultConfig targetSdkVersion 27 > >
Make the background transparent
name="Translucent" parent="AppTheme"> name="android:windowIsTranslucent">true
The screen orientation is fixed
android:name=".TranslucentActivity" android:configChanges="orientation" android:screenOrientation="portrait" android:theme="@style/Translucent" />
It crashes when I open the above mentioned TranslucentActivity on my Android 8.0 device.
cause
Android 8.0 Activity#onCreate contains the following processing, so it crashes when the above conditions are met.
public class Activity protected void onCreate(@Nullable Bundle savedInstanceState) // . if (getApplicationInfo().targetSdkVersion >= O_MR1 && mActivityInfo.isFixedOrientation()) final TypedArray ta = obtainStyledAttributes(com.android.internal.R.styleable.Window); final boolean isTranslucentOrFloating = ActivityInfo.isTranslucentOrFloating(ta); ta.recycle(); if (isTranslucentOrFloating) throw new IllegalStateException( "Only fullscreen opaque activities can request orientation"); > > // . > >
However, Android 8.1 has removed the above process.
Looking at the commit log of the Activity.java , it seems that the corrections are included in the following chronological order.
commit / tag | explanation |
---|---|
android-7.1.2_r36 | Android 7.1.2 |
3979159d1ac18c | Add the relevant section |
android-8.0.0_r1android-8.0.0_r36 | Android 8.0 |
a89b183e83f34cd4ecffa | Delete the relevant section |
android-8.1.0_r1 | Android 8.1 |
a4ceea0 | (deleted as well) |
The relationship between API level and tags was referenced on the following page. https://source.android.com/setup/start/build-numbers
Is it a bug? Is it a specification?
It’s completely predictable, but in the case of an Activity where the Activity behind you is visible, if you specify orientation, the Activity behind must also have the same orientation, and at that time the Activity behind you wanted to prevent screen rotation from happening even if the orientation is fixed. However, given the fact that it was removed in Android 8.1, at least the crashing behavior was not acceptable to Android developers. What is discussed below is not the Activity#onCreate part, but there is such an exchange. https://issuetracker.google.com/issues/68454482
Resolution
Of course, it can be solved by not meeting any of the four conditions that cause a crash. That said, I don’t think you can make Android 8.0 use or keep targetSdkVersion above 27 for the rest of your life, so I think it will be the following solution.
Supports screen rotation
Originally, I think it is best to respond to screen rotation! However, I feel like people who encounter this problem are developing apps that don’t support screen rotation
Behind orientation
If the source Activity is limited to your app, you can fix the orientation of the source Activity. In that case, if you set the orientation to behind, it will be in the same orientation as the Activity that is transparent behind it, so it will be fixed as it is. (In the case of transparent Activity, it seems that even if orientation is not specified, it will behave the same as when behind is specified, but I feel that it is good to be able to specify it if you specify behind)
Lowering targetSdkVersion for a moment
It’s completely brute force It seems to be working normally if you touch it appropriately, but operation can not be guaranteed
class TranslucentActivity : AppCompatActivity() override fun onCreate(savedInstanceState: Bundle?) if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) val targetSdkVersion = applicationInfo.targetSdkVersion applicationInfo.targetSdkVersion = Build.VERSION_CODES.O super.onCreate(savedInstanceState) applicationInfo.targetSdkVersion = targetSdkVersion > else super.onCreate(savedInstanceState) > setContentView(R.layout.activity_translucent) > >
Summary
If you raise the targetSdkVersion to 27, I think that it is okay if you check the operation with API level 27 (Android 8.1), but it seems that it is not so However, in this case, it crashes the moment you start Activity, so you want to prevent it by enhancing automatic testing.
Please comment if you have any comments or mistakes pointed out.