2

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

我所有的文件都在 GITHUB

第一个涉及标题中的错误。FirstRun.java:82alert.show();FirstRun.java:63_alertDialog.show();

我观察到的行为如下:

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

完整的logcat:

    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 会告诉我字符串urlt&url从未使用过。我如何编写它们以便它们遵循文件上显示的顺序?(读取etab_sel--> 确定并将值写入urlt--> 读取user_is--> 确定并将值写入url--> 将 JS 代码url作为变量之一执行。

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

4

2 回答 2

4

您的问题源于您使用的 2 个 Spinner FirstRun.java

微调器,微调器2

此外,我无法判断里面的代码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在初始化a 时调用。

所以,一旦你初始化R.id.spinner > onItemSelected()被调用 > case R.id.spinner > fallthrough > onStop() > editor.putBoolean("IsInitialized", true); > finish(); whilealertDialog并且alert正在显示 > 泄露的窗口

既然你打电话:

editor.putBoolean("IsInitialized", true);

in 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,替换falsetrue,做其他事情!

于 2013-09-02T00:49:51.740 回答
2

从您的代码中,我可以看到您正在完成对话框中的活动,您正在向该对话框传递相同活动的上下文。您的对话框正在参考已完成的活动。

AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
        alertDialog.setTitle("Remise \u00e0 z\u00e9ro");
        alertDialog.setMessage("Voulez-vous effacer tous vos param\u00e8tres (Identifiant, Mot de passe, type d\'accès de votre appareil?");
        alertDialog.setButton("Oui", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
                SharedPreferences.Editor editor = settings.edit();
                editor.putBoolean("IsInitialized", false);
                editor.putString("etab", "");
                editor.putString("name", "");
                editor.putString("key", "");
                editor.putString("manurl", manurl);
                editor.putString("user_is", "");
                editor.commit();
                finish();

            }
        });
        alertDialog.setButton("Non", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {
            }
        });
于 2013-08-30T14:58:24.193 回答