gpt4 book ai didi

android - Activity has leaked window that is originally added here & other issues, 关注

转载 作者:太空狗 更新时间:2023-10-29 16:19:29 30 4
gpt4 key购买 nike

我有几个问题想与大家分享。

All my files are on GITHUB

第一个与标题中的错误有关。 FirstRun.java:82 指的是 alert.show();FirstRun.java:63 指的是 alertDialog.show();

我观察到的行为是:

  1. 第一个 alertDialog 出现几秒钟
  2. 应用程序关闭(不是强制关闭)
  3. 当我开始重新启动应用程序时,会显示一个空白屏幕(请参阅以下问题),这意味着我的第二个 Activity 正在运行。我正在使用 SharedPrefs 查看是否应启动一项 Activity 。

完整的日志:

    32444-32444/carpedujourproductions.quickpronote E/WindowManager: Activity carpedujourproductions.quickpronote.FirstRun has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{967f7300 V.E..... R.....ID 0,0-729,594} that was originally added here
android.view.WindowLeaked: Activity carpedujourproductions.quickpronote.FirstRun has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{967f7300 V.E..... R.....ID 0,0-729,594} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:345)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:239)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:281)
at carpedujourproductions.quickpronote.FirstRun.onCreate(FirstRun.java:63)
at android.app.Activity.performCreate(Activity.java:5207)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2281)
at android.app.ActivityThread.access$600(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1263)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5124)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:110)
at dalvik.system.NativeStart.main(Native Method)

32444-32444/carpedujourproductions.quickpronote E/WindowManager: Activity carpedujourproductions.quickpronote.FirstRun has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{968738b8 V.E..... R......D 0,0-729,585} that was originally added here
android.view.WindowLeaked: Activity carpedujourproductions.quickpronote.FirstRun has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{968738b8 V.E..... R......D 0,0-729,585} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:345)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:239)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:281)
at android.app.AlertDialog$Builder.show(AlertDialog.java:951)
at carpedujourproductions.quickpronote.FirstRun.onCreate(FirstRun.java:82)
at android.app.Activity.performCreate(Activity.java:5207)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2281)
at android.app.ActivityThread.access$600(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1263)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5124)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:110)
at dalvik.system.NativeStart.main(Native Method)

另一件事:

SharedPrefs 对我做了奇怪的事情。第一次启动应用程序后,设置似乎已保存,并且 /data/data/carpedujourproductions.quickpronote/shared_prefs/ 中存在一个(非空)文件尽管我的任何根文件浏览器(ES;Solid)都无法读取它


最后:

我在处理条件时遇到了一些麻烦。如果您查看我的 MainActivity.java,Android Studio 会告诉我字符串 urlturl 从未使用过。我如何编写它们才能使它们遵循文件中显示的顺序? (读取 etab_sel --> 确定并写入 urlt --> 读取 user_is --> 确定并写入 url --> 以 url 作为变量之一执行 JS 代码。

非常非常感谢任何可以提供这些问题答案的人。这三者可能以某种方式相关。

最佳答案

您的问题源于您在 FirstRun.java 中使用的 2 个微调器:

Spinner, Spinner2

此外,我无法判断 onItemSelected() 中的代码是否符合您的预期:

@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
switch (parent.getId()) {
case R.id.spinner:
etab_sel = parent.getItemAtPosition(pos).toString();
Spinner2.setVisibility(View.VISIBLE);
case R.id.spinner2:
user_is = parent.getItemAtPosition(pos).toString();
onStop();
}
}

因为,目前,如果在 Spinner 上选择了一个项目,并且 case R.id.spinner 被启动,则会发生掉落并且 case R.id.spinner2 中的语句 也将被执行,导致调用 onStop()

这是预期的行为吗?或者,您是不是忘记放置 break; 语句?

此外,在 onStop() 中,您调用了 finish()。由于此时显示 alertDialogdialog,您会收到以下消息:

Activity carpedujourproductions.quickpronote.FirstRun has leaked window

Activity carpedujourproductions.quickpronote.FirstRun has leaked window

现在,更糟的是:

onItemSelected()Spinner 初始化时被调用。

因此,一旦您初始化 R.id.spinner > onItemSelected() 就会被调用 >> case R.id.spinner >> fallthrough >> onStop() 案例 R.id.spinner >> editor.putBoolean("IsInitialized", true); > finish();alertDialogalert 正在显示 > 泄漏的窗口

既然你打电话了:

editor.putBoolean("IsInitialized", true);

onStop() 中,FirstRun 永远不会在后续应用启动时启动:

(来自 MainActivity.java)

boolean IsInitialized = settings.getBoolean("IsInitialized", false);

if (IsInitialized == false) {
Intent intent = new Intent(MainActivity.this, FirstRun.class);
startActivity(intent);
finish();
}

如您所见,这里只有一个修复。您将不得不重新考虑 FirstRun 的逻辑方面。如果用户在首次启动时未从微调器中选择数据,您是否应该将 IsInitialized 设置为 true

要消除异常(目前),请执行以下操作:

// Declare two global boolean variables
boolean justStarted_1 = true;
boolean justStarted_2 = true;

....
....

@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

// Spinner is set; Ignore
if (justStarted_1) {

justStarted_1 = false;

// Spinner2 is set; ignore
} else if (justStarted_2) {

justStarted_2 = false;

// finally: here
} else {
switch (parent.getId()) {
case R.id.spinner:
etab_sel = parent.getItemAtPosition(pos).toString();
Spinner2.setVisibility(View.VISIBLE);
break;
case R.id.spinner2:
user_is = parent.getItemAtPosition(pos).toString();
onStop();
break;
}
}
}

另一件事:您必须不断卸载应用程序才能看到 FirstRun。目前一个简单的解决方法是使用:

editor.putBoolean("IsInitialized", false);

完成你在 FirstRun 上的工作,将 false 替换为 true,做点别的吧!

关于android - Activity has leaked window that is originally added here & other issues, 关注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18535473/

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