I started a new app with the master detail template.
When I try the app on my tablet, using the two-pane layout, it crashes with the exception in the title when I change orientation of the tablet. This happens only if the detail fragment has content.
The crash is in super.onCreate
line, I'm not even calling requestFeature
, so it's not even my code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_item_list);
if (findViewById(R.id.item_detail_container) != null) {
// The detail container view will be present only in the
// large-screen layouts (res/values-large and
// res/values-sw600dp). If this view is present, then the
// activity should be in two-pane mode.
mTwoPane = true;
// In two-pane mode, list items should be given the
// 'activated' state when touched.
((ItemListFragment) getSupportFragmentManager().findFragmentById(
R.id.item_list)).setActivateOnItemClick(true);
}
}
Stack trace:
12-14 23:18:44.716: E/AndroidRuntime(32065): FATAL EXCEPTION: main
12-14 23:18:44.716: E/AndroidRuntime(32065): Process: com.manor.barcam, PID: 32065
12-14 23:18:44.716: E/AndroidRuntime(32065): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.manor.barcam/com.manor.barcam.ItemListActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
12-14 23:18:44.716: E/AndroidRuntime(32065): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
12-14 23:18:44.716: E/AndroidRuntime(32065): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
12-14 23:18:44.716: E/AndroidRuntime(32065): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3738)
12-14 23:18:44.716: E/AndroidRuntime(32065): at android.app.ActivityThread.access$900(ActivityThread.java:135)
12-14 23:18:44.716: E/AndroidRuntime(32065): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1202)
12-14 23:18:44.716: E/AndroidRuntime(32065): at android.os.Handler.dispatchMessage(Handler.java:102)
12-14 23:18:44.716: E/AndroidRuntime(32065): at android.os.Looper.loop(Looper.java:136)
12-14 23:18:44.716: E/AndroidRuntime(32065): at android.app.ActivityThread.main(ActivityThread.java:5017)
12-14 23:18:44.716: E/AndroidRuntime(32065): at java.lang.reflect.Method.invokeNative(Native Method)
12-14 23:18:44.716: E/AndroidRuntime(32065): at java.lang.reflect.Method.invoke(Method.java:515)
12-14 23:18:44.716: E/AndroidRuntime(32065): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
12-14 23:18:44.716: E/AndroidRuntime(32065): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
12-14 23:18:44.716: E/AndroidRuntime(32065): at dalvik.system.NativeStart.main(Native Method)
12-14 23:18:44.716: E/AndroidRuntime(32065): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
12-14 23:18:44.716: E/AndroidRuntime(32065): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:249)
12-14 23:18:44.716: E/AndroidRuntime(32065): at android.app.Activity.requestWindowFeature(Activity.java:3298)
12-14 23:18:44.716: E/AndroidRuntime(32065): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:63)
12-14 23:18:44.716: E/AndroidRuntime(32065): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
12-14 23:18:44.716: E/AndroidRuntime(32065): at com.manor.barcam.ItemListActivity.onCreate(ItemListActivity.java:54)
12-14 23:18:44.716: E/AndroidRuntime(32065): at android.app.Activity.performCreate(Activity.java:5231)
12-14 23:18:44.716: E/AndroidRuntime(32065): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-14 23:18:44.716: E/AndroidRuntime(32065): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
12-14 23:18:44.716: E/AndroidRuntime(32065): ... 12 more
How can I solve it?
Thanks.
I got the same issue but it happened when the app was killed in the background by the OS. I traced the problem to ActionBarActivityDelegateICS.java from appcompat where the requestWindowFeature() is called after super.onCreate:
super.onCreate(savedInstanceState);
if (mHasActionBar) {
// If action bar is requested by inheriting from the appcompat theme,
// the system will not know about that. So explicitly request for an action bar.
mActivity.requestWindowFeature(WindowCompat.FEATURE_ACTION_BAR);
}
if (mOverlayActionBar) {
mActivity.requestWindowFeature(WindowCompat.FEATURE_ACTION_BAR_OVERLAY);
}
So I imported the appcompat from git and changed the above code to call the super.onCreate() after .requestWindowFeature() which solved the problem. Also submitted a bug report to Google
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With