1

I have a tutorial activity within my app which contains a bunch of slides with some details on how to use the app. I wanted my whole app to be in PORTRAIT mode only so i created a custom Application class with the code below :

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) {

        }
    });
}

}

Now, the issue is that the tutorial used to work just fine whenever i would install it for the first time but now it just crashes and throws an IllegalArgumentException exception saying that Only fullscreen activities can request orientation. After researching for a bit, i realized that this is Google's error(if i'm wrong please correct me) but i haven't found a way around it.The exception points me to my custom Application class and to my Tutorial class which you can see below.However, i haven't found the issue.Any ideas?

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());
}

}

Here's the full exception:

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$1.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)

*If anyone is interested, here's the part where i use the custom application class in the Manifest.xml file:

<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">
Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
Stelios Papamichail
  • 955
  • 2
  • 19
  • 57

1 Answers1

1

Thanks to @Khemraj 's link i managed to solve the issue by surrounding the contents of the custom Application class's onActivityCreated method with the following if statement:

if(android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
TheKarlo95
  • 1,144
  • 9
  • 17
Stelios Papamichail
  • 955
  • 2
  • 19
  • 57
  • 1
    I don't think it's a good idea. You have just disabled the orientation setting for ALL activities on devices with Oreo version. Not just the problematic ones. – Elyakim Levi Jul 13 '20 at 11:19