抛出:IllegalArgumentException:窗口被加入后窗口类型不能改变 [英] IllegalArgumentException: Window type can not be changed after the window is added
问题描述
我已经试过了意见这里,建议<一href="http://stackoverflow.com/questions/29594412/android-error-illegalargumentexception-window-type-can-not-be-changed-after-the">here,建议<一href="http://stackoverflow.com/questions/19568078/android-error-illegalargumentexception-window-type-can-not-be-changed-after">here,我在我的基本活动注释掉onAttachedToWindow()。我从这个类,BaseActivity两项活动继承。一跑,和一个没有。可能是什么区别?我的目标SDK是19;它改变到12都没有区别。这是我的onCreate的BaseActivity:
I've tried the advice here, the advice here, the advice here, I've commented out the onAttachedToWindow() in my Base Activity. I have two Activities inheriting from this class, BaseActivity. One runs, and one does not. What could be the difference? My target SDK is 19; changing it to 12 makes no difference. Here is my onCreate for BaseActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onAttachedToWindow();
super.onCreate(savedInstanceState);
....
}
当浏览到第二个活动,通过code步进,它使通过的onCreate(),onResume(),然后崩溃。
When navigating to the second activity, stepping through the code, it makes it through onCreate(), onResume(), then crashes.
这可能是什么问题?
堆栈跟踪:
06-26 13:41:57.963 28667-28667/com.assistek.ediary E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.assistek.ediary, PID: 28667
java.lang.IllegalArgumentException: Window type can not be changed after the window is added.
at android.os.Parcel.readException(Parcel.java:1550)
at android.os.Parcel.readException(Parcel.java:1499)
at android.view.IWindowSession$Stub$Proxy.relayout(IWindowSession.java:903)
at android.view.ViewRootImpl.relayoutWindow(ViewRootImpl.java:5301)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1507)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
修改:如果我改变目标API 12,并把所有从的onCreate
的变化,到 onAttachedToWindow
,我能得到这个例外消失,但我想目标SDK为19。
EDIT: if I change to target API 12 and put all of the changes in from onCreate
into onAttachedToWindow
, I can get this exception to go away, but I'd like the target SDK to be 19.
我的新的onCreate():
My new onCreate():
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
...
}
我的新 onAttachedToWindow():
My new onAttachedToWindow():
@Override
public void onAttachedToWindow() {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
这仅适用于目标API 12
This only works with target API 12.
推荐答案
尝试使用此窗:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_adjectives);
这篇关于抛出:IllegalArgumentException:窗口被加入后窗口类型不能改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!