AndroidRuntimeException: requestFeature() must be called before adding content exclusive to Honeycomb 3.1 - 3.2.1
Asked Answered
P

1

6

After last update my app has the following issue:

java.lang.RuntimeException: Unable to start activity ComponentInfo{my.package/my.package.MyMainActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1818)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1834)
at android.app.ActivityThread.access$500(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1027)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4126)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:214)
at android.support.v7.app.ActionBarActivityDelegateHC.onCreate(ActionBarActivityDelegateHC.java:38)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
at my.package.MyBaseActivity.onCreate(MyBaseActivity.java:68)
at my.package.MyApiServiceActivity.onCreate(MyApiServiceActivity.java:51)
at my.package.MyActivity.onCreate(MyActivity.java:88)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1782)
... 11 more

However, I'm never calling requestWindowFeature or similar. There are no dialogues involved either. The report itself comes from BugSense, I never had this problem myself. It's a fairly popular app and the issue is exclusive to Android Honeycomb: 3.2, 3.2.1 and 3.1. It didn't happen in previous version of the app. The only change in onCreate function since the update is the fact I switched from ActionBarSherlock to ActionBarCompat.

Anyone spotted this issue as well and/or has any ideas how to overcome the problem?

EDIT: I am adding the link to the source for ActionBarActivityDelegateHC from v7 package where the crash stack trace (Caused by...) starts. There the requestFeature call happens, but it's called correctly, even before super.onCreate.

I use Gradle to import the package: compile 'com.android.support:appcompat-v7:18.0.+'

Pub answered 7/10, 2013 at 7:43 Comment(4)
the same issue during rotation, I suppose to fix it by locking orientation on honeycomb devices. there is too sad statistics for honeycomb: developer.android.com/about/dashboards/index.html#Platform , so we won't care about it )Zaxis
@shomeser Do you know if this issue specific to rotation?Pub
I reproduce it only during rotation, so I will lock landscape orientation on honeycomb, but if you find any suitable solution, I'll use itZaxis
I got this crash if when i used setHasOptionsMenu(true); in fragment onCreate()Hosey
P
6

So looks like solution from @shomeser (comments to the question) is a way to go for the time being.

There are two ways to compromise:

  • If you don't have different layouts for landscape and portrait, you can disable the orientation changes (in AndroidManifest: android:configChanges="screenSize|orientation")
  • If you have some handling on orientation change and can't use "configChanges", you can lock the orientation (in onCreate)
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
            || Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB_MR2)
    {
        this.setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
  • and finally my least favourite (Posting this for completion though), drop ABC and go back to ABS.

I also posted a ticket on Android Issue Tracker, but it being a Honeycomb issue, I don't expect getting an answer.

UPDATE: After releasing app with locked orientation for specific Honeycomb devices, I still see this crash being reported, though less frequent.

UPDATE 2: Issue was fixed! Now just wait for the release of new support lib: google issue tracker

Pub answered 11/10, 2013 at 10:39 Comment(5)
do you have stacktrace of crash, is it the same as first one? and did you test your application on real device?Zaxis
@shomeser it's the same stack trace - it crashes on activities that have locked orientation; the bug report points to real devices (always the same Honeycomb versions).Pub
give me a link to your application, please. I think you can reproduce it after pause and resume.Zaxis
Same happens on HONEYCOMB (API 11). I suggest you edit the IF for if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB_MR2) .Mahatma
@Mahatma thanks! I corrected response with your suggestions. Now let's hope the new release of support package will appear soon to fix this issue permanently.Pub

© 2022 - 2024 — McMap. All rights reserved.