方向改变时与内存/线程相关的崩溃?
朋友们,
onCreate() 我正在使用异步线程从 web 服务加载数据。 当线程启动时,它会在屏幕上显示进度条并加载数据。
我遇到的一个突然的问题是,当我开始显示活动进度条时,我改变手机的方向,第二个线程启动并开始运行。
应用程序崩溃。(创新目标异常之类的)。
这是日志猫,任何人都可以指导我解决这个问题的方法是什么?
代码很简单
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.searchbanks);
threadBank = new AsyncBanks();
threadBank.execute("","");
}
04-29 16:08:26.811: ERROR/WindowManager(430): Activity com.FindMe.SearchBanks has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44f64f98 that was originally added here
04-29 16:08:26.811: ERROR/WindowManager(430): android.view.WindowLeaked: Activity com.FindMe.SearchBanks has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44f64f98 that was originally added here
04-29 16:08:26.811: ERROR/WindowManager(430): at android.view.ViewRoot.<init>(ViewRoot.java:247)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.view.Window$LocalWindowManager.addView(Window.java:424)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.app.Dialog.show(Dialog.java:241)
04-29 16:08:26.811: ERROR/WindowManager(430): at com.FindMe.SearchBanks$AsyncBanks.onPreExecute(SearchBanks.java:133)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.os.AsyncTask.execute(AsyncTask.java:391)
04-29 16:08:26.811: ERROR/WindowManager(430): at com.FindMe.SearchBanks.LoadRecords(SearchBanks.java:115)
04-29 16:08:26.811: ERROR/WindowManager(430): at com.FindMe.SearchBanks.onCreate(SearchBanks.java:76)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.os.Handler.dispatchMessage(Handler.java:99)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.os.Looper.loop(Looper.java:123)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-29 16:08:26.811: ERROR/WindowManager(430): at java.lang.reflect.Method.invokeNative(Native Method)
04-29 16:08:26.811: ERROR/WindowManager(430): at java.lang.reflect.Method.invoke(Method.java:521)
04-29 16:08:26.811: ERROR/WindowManager(430): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-29 16:08:26.811: ERROR/WindowManager(430): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-29 16:08:26.811: ERROR/WindowManager(430): at dalvik.system.NativeStart.main(Native Method)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): java.lang.IllegalArgumentException: View not attached to window manager
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:200)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.view.Window$LocalWindowManager.removeView(Window.java:432)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.app.Dialog.dismissDialog(Dialog.java:278)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.app.Dialog.access$000(Dialog.java:71)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.app.Dialog$1.run(Dialog.java:111)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.app.Dialog.dismiss(Dialog.java:268)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at com.FindMe.SearchBanks$AsyncBanks.onPostExecute(SearchBanks.java:197)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at com.FindMe.SearchBanks$AsyncBanks.onPostExecute(SearchBanks.java:1)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.os.AsyncTask.finish(AsyncTask.java:417)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.os.AsyncTask.access$300(AsyncTask.java:127)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.os.Handler.dispatchMessage(Handler.java:99)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.os.Looper.loop(Looper.java:123)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at java.lang.reflect.Method.invokeNative(Native Method)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at java.lang.reflect.Method.invoke(Method.java:521)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at dalvik.system.NativeStart.main(Native Method)
Friends,
onCreate() I am loading data from webservice using Async thread.
when thread is started it shows progress bar on screen and loads data.
A sudden problem I have faced is when I start that activity progress bar is shown I change orientation of my phone second thread starts &
Application crashes.(Inovation Target Exception something like that).
Here is the log cat any one guide me what is the solution to this problem?
Code is simple
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.searchbanks);
threadBank = new AsyncBanks();
threadBank.execute("","");
}
04-29 16:08:26.811: ERROR/WindowManager(430): Activity com.FindMe.SearchBanks has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44f64f98 that was originally added here
04-29 16:08:26.811: ERROR/WindowManager(430): android.view.WindowLeaked: Activity com.FindMe.SearchBanks has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44f64f98 that was originally added here
04-29 16:08:26.811: ERROR/WindowManager(430): at android.view.ViewRoot.<init>(ViewRoot.java:247)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.view.Window$LocalWindowManager.addView(Window.java:424)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.app.Dialog.show(Dialog.java:241)
04-29 16:08:26.811: ERROR/WindowManager(430): at com.FindMe.SearchBanks$AsyncBanks.onPreExecute(SearchBanks.java:133)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.os.AsyncTask.execute(AsyncTask.java:391)
04-29 16:08:26.811: ERROR/WindowManager(430): at com.FindMe.SearchBanks.LoadRecords(SearchBanks.java:115)
04-29 16:08:26.811: ERROR/WindowManager(430): at com.FindMe.SearchBanks.onCreate(SearchBanks.java:76)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.os.Handler.dispatchMessage(Handler.java:99)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.os.Looper.loop(Looper.java:123)
04-29 16:08:26.811: ERROR/WindowManager(430): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-29 16:08:26.811: ERROR/WindowManager(430): at java.lang.reflect.Method.invokeNative(Native Method)
04-29 16:08:26.811: ERROR/WindowManager(430): at java.lang.reflect.Method.invoke(Method.java:521)
04-29 16:08:26.811: ERROR/WindowManager(430): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-29 16:08:26.811: ERROR/WindowManager(430): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-29 16:08:26.811: ERROR/WindowManager(430): at dalvik.system.NativeStart.main(Native Method)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): java.lang.IllegalArgumentException: View not attached to window manager
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:200)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.view.Window$LocalWindowManager.removeView(Window.java:432)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.app.Dialog.dismissDialog(Dialog.java:278)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.app.Dialog.access$000(Dialog.java:71)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.app.Dialog$1.run(Dialog.java:111)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.app.Dialog.dismiss(Dialog.java:268)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at com.FindMe.SearchBanks$AsyncBanks.onPostExecute(SearchBanks.java:197)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at com.FindMe.SearchBanks$AsyncBanks.onPostExecute(SearchBanks.java:1)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.os.AsyncTask.finish(AsyncTask.java:417)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.os.AsyncTask.access$300(AsyncTask.java:127)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.os.Handler.dispatchMessage(Handler.java:99)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.os.Looper.loop(Looper.java:123)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at java.lang.reflect.Method.invokeNative(Native Method)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at java.lang.reflect.Method.invoke(Method.java:521)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-29 16:08:28.652: ERROR/AndroidRuntime(430): at dalvik.system.NativeStart.main(Native Method)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
即使您关闭对话框以便可以重新创建它,销毁对话框的系统与您将关闭对话框的生命周期方法之间似乎也存在竞争条件。我很少收到有关在配置更改时关闭不存在的对话框的崩溃报告。
我建议捕获并忽略 Dialog.dismiss() 中的异常以处理竞争条件。这就是我所做的,它解决了我的问题。
史蒂夫@WhitneyApps
Even if you dismiss your dialog so that you can recreate it, there seems to be a race condition between the system destroying the dialog and the lifecycle methods where you would dismiss it. Very rarely I get a crash report about dismissing a non-existent dialog at configuration change time.
I suggest catching and ignoring the exception in Dialog.dismiss() just to handle the race condition. That's what I've done and it's cleared up my problem.
Steve @ WhitneyApps
最后我自己得到了答案。
如何处理显示 ProgressDialog 时的方向变化?< /a>
和
如何在定向时处理 Activity变化?
Finally i got answer myself.
How to deal with orientation change with a ProgressDialog showing?
And
How to handle Activity when Orientation changes?