Android Studio 中的 IllegalStateException:只有全屏活动可以请求方向

IllegalStateException in Android Studio: Only Fullscreen activities can request orientation

我的应用程序中有一个教程 activity,其中包含大量幻灯片,其中包含有关如何使用该应用程序的一些详细信息。我希望我的整个应用程序仅处于 PORTRAIT 模式,所以我使用以下代码创建了一个自定义 Application class :

public class DokkanCardsApplication extends Application {
@Override
public void onCreate() {
    super.onCreate();
    registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
        @Override
        public void onActivityCreated(Activity activity, Bundle bundle) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }

        @Override
        public void onActivityStarted(Activity activity) {

        }

        @Override
        public void onActivityResumed(Activity activity) {

        }

        @Override
        public void onActivityPaused(Activity activity) {

        }

        @Override
        public void onActivityStopped(Activity activity) {

        }

        @Override
        public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {

        }

        @Override
        public void onActivityDestroyed(Activity activity) {

        }
    });
}

}

现在的问题是,每当我第一次安装教程时,它都可以正常工作,但现在它崩溃并抛出 IllegalArgumentException 异常,提示 仅全屏活动可以要求方向。经过一番研究,我意识到这是 Google 的错误(如果我错了请纠正我)但我还没有找到解决方法 it.The 异常指向我的自定义 Application class 和我的教程 class 你可以看到 below.However,我还没有找到 issue.Any 的想法?

Tutorial.java:

public class Tutorial extends MaterialIntroActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addSlide(new SlideFragmentBuilder()
            .title("Main Screen")
            .description("Search through the entire Dokkan Cards database and find any card you like.")
            .image(R.drawable.image_main)
            .backgroundColor(R.color.mainScreen)
            .buttonsColor(R.color.colorPrimaryGLB)
            .build());


    addSlide(new SlideFragmentBuilder()
            .title("Tap & Long-Press Actions")
            .description("Tap on any card icon to view it's details or Long-press on it to add it to either one of your boxes")
            .image(R.drawable.image_long_tap)
            .backgroundColor(R.color.long_tap)
            .buttonsColor(R.color.colorPrimaryGLB)
            .build());

    addSlide(new SlideFragmentBuilder()
            .title("Side Menu")
            .description("Swipe from left to right to access a handful of menu options")
            .image(R.drawable.image_menu_slide)
            .backgroundColor(R.color.side_menu)
            .buttonsColor(R.color.colorPrimaryGLB)
            .build());

    addSlide(new SlideFragmentBuilder()
            .title("Auto-Save")
            .description("This app saves your box data automatically when you close the app so that you don't have to worry about saving manually")
            .image(R.drawable.image_auto_save)
            .backgroundColor(R.color.auto_save)
            .buttonsColor(R.color.colorPrimaryGLB)
            .build());

    addSlide(new SlideFragmentBuilder()
            .title("Data Security")
            .description("Your data is 100% safe since it cannot be accessed by anyone else.All data are stored locally on your device and not on a server or cloud")
            .image(R.drawable.image_data_security)
            .backgroundColor(R.color.data_security)
            .buttonsColor(R.color.colorPrimaryGLB)
            .build());

    addSlide(new SlideFragmentBuilder()
            .title("Donations")
            .description("Although donations are not mandatory, they help a lot in the app's development process. You can submit your donation via the website tab in the app's side menu.")
            .image(R.drawable.image_donation)
            .backgroundColor(R.color.donations)
            .buttonsColor(R.color.colorPrimaryGLB)
            .build());

   addSlide(new TutorialDisclaimerSlide());

    addSlide(new SlideFragmentBuilder()
            .title("That's it")
            .description("That's the end of this tutorial.You can access it at any time from the top right corner of the app")
            .image(R.drawable.image_tutorial)
            .backgroundColor(R.color.tutorial_end)
            .buttonsColor(R.color.colorPrimaryGLB)
            .build());
}

}

这是完整的例外情况:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dcv.spdesigns.dokkancards/com.dcv.spdesigns.dokkancards.ui.Tutorial}: java.lang.IllegalStateException: Only fullscreen activities can request orientation
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2955)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6938)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
 Caused by: java.lang.IllegalStateException: Only fullscreen activities can request orientation
    at android.os.Parcel.readException(Parcel.java:1966)
    at android.os.Parcel.readException(Parcel.java:1904)
    at android.app.IActivityManager$Stub$Proxy.setRequestedOrientation(IActivityManager.java:6186)
    at android.app.Activity.setRequestedOrientation(Activity.java:5831)
    at com.dcv.spdesigns.dokkancards.presenter.DokkanCardsApplication.onActivityCreated(DokkanCardsApplication.java:20)
    at android.app.Application.dispatchActivityCreated(Application.java:221)
    at android.app.Activity.onCreate(Activity.java:1067)
    at android.support.v4.app.SupportActivity.onCreate(ComponentActivity.java:71)
    at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:325)
    at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:85)
    at agency.tango.materialintroscreen.MaterialIntroActivity.onCreate(MaterialIntroActivity.java:73)
    at com.dcv.spdesigns.dokkancards.ui.Tutorial.onCreate(Tutorial.java:17)
    at android.app.Activity.performCreate(Activity.java:7174)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2908)

*如果有人感兴趣,这是我在 Manifest.xml 文件中使用自定义应用程序 class 的部分:

<application
    android:name=".presenter.DokkanCardsApplication"
    android:allowBackup="true"
    android:fullBackupContent="@xml/backup_descriptor"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

感谢@Khemraj 的 link 我设法通过围绕 自定义应用程序 class 的 [=11] 的内容解决了这个问题=] 方法与以下 if 语句:

if(android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}