gpt4 book ai didi

android - IllegalArgumentException : Window type can not be changed after the window is added

转载 作者:IT老高 更新时间:2023-10-28 23:06:55 27 4
gpt4 key购买 nike

我已经尝试了 here 的建议, 建议 here , 建议 here ,我已经在我的基本 Activity 中注释掉了 onAttachedToWindow() 。我有两个继承自此类 BaseActivity 的 Activity 。一个跑,一个不跑。有什么区别?我的目标 SDK 是 19;将其更改为 12 没有区别。这是我对 BaseActivity 的 onCreate:

    @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);

....
}

当导航到第二个 Activity 时,单步执行代码,它会通过 onCreate()、onResume(),然后崩溃。

可能是什么问题?

堆栈跟踪:

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)

EDIT:如果我更改为目标 API 12 并将所有更改从 onCreate 放入 onAttachedToWindow,我可以得到这个异常离开,但我希望目标 SDK 为 19。

我的 onCreate():

@Override
protected void onCreate(Bundle savedInstanceState) {

requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
...
}

我的 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。

回答 Min target must be less than 14 when WindowManager.LayoutParams.TYPE_KEYGUARD used

最佳答案

尝试将其用于窗口:

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_adjectives);

关于android - IllegalArgumentException : Window type can not be changed after the window is added,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31081968/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com