在我的应用程序中,每次启动应用程序时,我都想执行一个 php 脚本并相应地加载应用程序。因此我创建了一个静态布尔变量
boolean firstRun = false;
在我的 onStart 中,我添加了以下代码:
// If images need to be downloaded, call SProgressAsyncTask class
public void onStart() {
super.onStart();
if (firstRun) {
sat = new SProgressAsyncTask(this);
sat.execute("");
firstRun = false;
}
}
在索尼的朋友设备上,它可以完美运行,即上面的代码只执行一次,即应用程序启动。在我的 Sony Xperia P 上,每次应用程序进入此主屏幕时都会执行上述代码。当 firstRun 设置为 false 时,为什么上面的代码每次回到这个活动时都会运行。我尝试在我的设备上进行调试,但出现以下错误:
10-22 17:41:49.879: E/WindowManager(30235): Activity org.mumbai77.core.Mumbai77Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4143a460 that was originally added here
10-22 17:41:49.879: E/WindowManager(30235): android.view.WindowLeaked: Activity org.mumbai77.core.Mumbai77Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4143a460 that was originally added here
10-22 17:41:49.879: E/WindowManager(30235): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:344)
10-22 17:41:49.879: E/WindowManager(30235): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
10-22 17:41:49.879: E/WindowManager(30235): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
10-22 17:41:49.879: E/WindowManager(30235): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
10-22 17:41:49.879: E/WindowManager(30235): at android.view.Window$LocalWindowManager.addView(Window.java:537)
10-22 17:41:49.879: E/WindowManager(30235): at android.app.Dialog.show(Dialog.java:278)
10-22 17:41:49.879: E/WindowManager(30235): at org.mumbai77.components.ProgressAsyncTask.onPreExecute(ProgressAsyncTask.java:56)
10-22 17:41:49.879: E/WindowManager(30235): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561)
10-22 17:41:49.879: E/WindowManager(30235): at android.os.AsyncTask.execute(AsyncTask.java:511)
10-22 17:41:49.879: E/WindowManager(30235): at org.mumbai77.core.Mumbai77Activity.onStart(Mumbai77Activity.java:170)
10-22 17:41:49.879: E/WindowManager(30235): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1133)
10-22 17:41:49.879: E/WindowManager(30235): at android.app.Activity.performStart(Activity.java:4475)
10-22 17:41:49.879: E/WindowManager(30235): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1940)
10-22 17:41:49.879: E/WindowManager(30235): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
10-22 17:41:49.879: E/WindowManager(30235): at android.app.ActivityThread.access$600(ActivityThread.java:127)
10-22 17:41:49.879: E/WindowManager(30235): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
10-22 17:41:49.879: E/WindowManager(30235): at android.os.Handler.dispatchMessage(Handler.java:99)
10-22 17:41:49.879: E/WindowManager(30235): at android.os.Looper.loop(Looper.java:137)
10-22 17:41:49.879: E/WindowManager(30235): at android.app.ActivityThread.main(ActivityThread.java:4441)
10-22 17:41:49.879: E/WindowManager(30235): at java.lang.reflect.Method.invokeNative(Native Method)
10-22 17:41:49.879: E/WindowManager(30235): at java.lang.reflect.Method.invoke(Method.java:511)
10-22 17:41:49.879: E/WindowManager(30235): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
10-22 17:41:49.879: E/WindowManager(30235): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
10-22 17:41:49.879: E/WindowManager(30235): at dalvik.system.NativeStart.main(Native Method)
我更改了 SProgressAsyncTask 类,而不是传递 Activity,而是传递了 Context - getApplicationContext(),但这让情况变得更糟。
谁能帮我知道,为什么 onStart if (firstRun) 每次都执行而不是只执行一次。
顺便说一句,我和我朋友的设备都只有 ICECREAM Os。
从 mlast 5-6 天以来,我一直停留在这个阶段,任何帮助都非常感谢。请帮我摆脱这个错误。