0

我有一个应用程序,它在纵向和横向中使用两种布局。为了在初始加载时从 web 加载内容,我使用了 AsyncTask 和进度条。

我检查了这个。由于我有两种布局,这不是解决方案。

下面给出了例外情况。

> 05-08 16:44:43.483: E/WindowManager(20138): Activity com.news.one has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@482b0130 that was originally added here
05-08 16:44:43.483: E/WindowManager(20138): android.view.WindowLeaked: Activity com.news.one has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@482b0130 that was originally added here
05-08 16:44:43.483: E/WindowManager(20138):     at android.view.ViewRoot.<init>(ViewRoot.java:247)
05-08 16:44:43.483: E/WindowManager(20138):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:181)
05-08 16:44:43.483: E/WindowManager(20138):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:124)
05-08 16:44:43.483: E/WindowManager(20138):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
05-08 16:44:43.483: E/WindowManager(20138):     at android.app.Dialog.show(Dialog.java:241)
05-08 16:44:43.483: E/WindowManager(20138):     at com.news.one$DownloadNews.onPreExecute(AdaDeranaTabActivity.java:365)
05-08 16:44:43.483: E/WindowManager(20138):     at android.os.AsyncTask.execute(AsyncTask.java:391)
05-08 16:44:43.483: E/WindowManager(20138):     at com.news.one.onCreate(AdaDeranaTabActivity.java:201)
05-08 16:44:43.483: E/WindowManager(20138):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-08 16:44:43.483: E/WindowManager(20138):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-08 16:44:43.483: E/WindowManager(20138):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-08 16:44:43.483: E/WindowManager(20138):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-08 16:44:43.483: E/WindowManager(20138):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-08 16:44:43.483: E/WindowManager(20138):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 16:44:43.483: E/WindowManager(20138):     at android.os.Looper.loop(Looper.java:123)
05-08 16:44:43.483: E/WindowManager(20138):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-08 16:44:43.483: E/WindowManager(20138):     at java.lang.reflect.Method.invokeNative(Native Method)
05-08 16:44:43.483: E/WindowManager(20138):     at java.lang.reflect.Method.invoke(Method.java:521)
05-08 16:44:43.483: E/WindowManager(20138):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
05-08 16:44:43.483: E/WindowManager(20138):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-08 16:44:43.483: E/WindowManager(20138):     at dalvik.system.NativeStart.main(Native Method)
05-08 16:44:54.065: E/AndroidRuntime(20138): FATAL EXCEPTION: main
05-08 16:44:54.065: E/AndroidRuntime(20138): java.lang.IllegalArgumentException: View not attached to window manager
05-08 16:44:54.065: E/AndroidRuntime(20138):    at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:388)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:233)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at android.view.Window$LocalWindowManager.removeView(Window.java:432)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at android.app.Dialog.dismissDialog(Dialog.java:278)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at android.app.Dialog.access$000(Dialog.java:71)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at android.app.Dialog$1.run(Dialog.java:111)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at android.app.Dialog.dismiss(Dialog.java:268)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at com.news.one$DownloadNews.onPostExecute(AdaDeranaTabActivity.java:376)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at com.news.one$DownloadNews.onPostExecute(AdaDeranaTabActivity.java:1)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at android.os.AsyncTask.finish(AsyncTask.java:417)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at android.os.AsyncTask.access$300(AsyncTask.java:127)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at android.os.Looper.loop(Looper.java:123)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at android.app.ActivityThread.main(ActivityThread.java:4627)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at java.lang.reflect.Method.invokeNative(Native Method)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at java.lang.reflect.Method.invoke(Method.java:521)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-08 16:44:54.065: E/AndroidRuntime(20138):    at dalvik.system.NativeStart.main(Native Method)

有没有一种方法可以锁定旋转变化,直到应用程序自行加载?

或者和其他想法?

提前致谢。

4

4 回答 4

1

当您切换方向时,Android 将创建一个新视图。您可能会崩溃,因为您的后台线程正在尝试更改旧线程的状态。(它也可能有问题,因为您的后台线程不在 UI 线程上)。这些是解决方案:

进度对话框和后台线程处于活动状态时如何处理屏幕方向更改?

旋转Android上的活动重启

于 2013-01-31T01:31:12.097 回答
0

progressDialog.dismiss()我在方法中调用了onDestroy()

在方向改变期间,活动重新开始。所以在重启之前我们必须销毁当前的progressDialog。这可以解决问题。:D

于 2012-05-09T08:02:57.803 回答
-1

You are getting WindowLeak Exception, this exception occur when any dialog/progressBar uses the reference of context and context reference lost due to orientation change.

So put below code for all activity tag in manifest file.

android:configChanges="orientation|keyboard"

example:

<activity
            android:name=".InviteActivity" android:configChanges="orientation|keyboard"/>

and use below code in activity

 @Override
    public void onConfigurationChanged(Configuration newConfig)
    {
        setContentView(R.layout.YOUR_LAYOUT);
        super.onConfigurationChanged(newConfig);
    }
于 2012-05-08T12:20:44.740 回答
-1

我遇到了同样的问题并解决了这个问题,我在开始同步之前锁定了方向并在同步后将其设置回来:

// before
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

// after synchronisation: 
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
于 2012-05-09T05:21:07.037 回答