I have tried
android:screenOrientation="portrait"
and
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
but it is crashing the app, Is there any alternative method for this to work in Android 8.0.0+?
Logcat:
FATAL EXCEPTION: main
Process: in.ajtech.finX, PID: 15077
java.lang.RuntimeException: Unable to start activity ComponentInfo{in.ajtech.finX/in.ajtech.finX.CalendarActivity}: java.lang.IllegalStateException: Only fullscreen activities can request orientation
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IllegalStateException: Only fullscreen activities can request orientation
at android.os.Parcel.readException(Parcel.java:1950)
at android.os.Parcel.readException(Parcel.java:1888)
at android.app.IActivityManager$Stub$Proxy.setRequestedOrientation(IActivityManager.java:5675)
at android.app.Activity.setRequestedOrientation(Activity.java:5739)
at in.ajtech.finX.CalendarActivity.onCreate(CalendarActivity.java:55)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
BUG
Read
Only fullscreen activities can request orientation
You should use
AppCompatActivity
instead ofActivity
.let your activity extend
AppCompatActivity
.JAVA
Kotlin
FYI
From
Setting Up the App Bar
.DEMO
Set your style
You can set the property from you manifest file, inside each activity, add this line
android:screenOrientation="portrait"
It's android sdk(27) issue , you can't use
portrait
withTranslucent
so reduce your target sdk to26
or removeTranslucent
theme or removeportrait
mode.Repacing
extents Activity
toAppCompatActivity
fixed the issue. Thank you for all your helpIn
AndroidManifest.xml
make the following changes:For opaque activities, i.e. full-screen, set:
Note that the theme should be NOT Translucent.
For transclusent activities, i.e. pop-up dialogs etc, set:
Note that screenOrientation is not specified here. You can use Translucent themes.
This works without downgrading SDK version.