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
但是,我从不调用requestWindowFeature或类似的东西.也没有涉及对话.该报告本身来自BugSense,我自己从未遇到过这个问题.这是一个相当受欢迎的应用程序,该问题是Android Honeycomb独有的:3.2,3.2.1和3.1.它在以前版本的应用程序中没有发生.自更新以来onCreate函数的唯一变化是我从ActionBarSherlock切换到ActionBarCompat的事实.
任何人都发现了这个问题和/或有任何想法如何克服这个问题?
编辑:@H_404_9@我正在从v7包添加链接到the source for ActionBarActivityDelegateHC
,其中崩溃堆栈跟踪(由…引起)启动.在那里发生了requestFeature调用,但它被正确调用,甚至在super.onCreate之前.
我使用Gradle导入包:compile’com.android.support:appcompat-v7:18.0. “
解决方法
有两种妥协方式:
>如果横向和纵向没有不同的布局,则可以禁用方向更改(在AndroidManifest中:android:configChanges =“screenSize | orientation”)@H_404_9@>如果您对方向更改有一些处理并且无法使用“configChanges”,则可以锁定方向(在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); }
>最后我最不喜欢(虽然发布完毕),放弃ABC并回到ABS.
我还发布了一个ticket on Android Issue Tracker,但这是一个Honeycomb问题,我不希望得到答案.
更新:在发布具有特定Honeycomb设备的锁定方向的应用程序后,我仍然看到报告此崩溃,但不太频繁.
更新2:@H_404_9@问题已修复!现在只等待新支持lib:google issue tracker的发布