0

I have a application which use two layouts in portrait ans landscape. To load content form web at the initial load I use a AsyncTask and a progress bar.

I checked this. Since I have two layouts this is not the solution.

The exception is given below.

> 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)

Is there a method to lock the rotation change till the application loads it self?

Or and other idea?

Thanks in advance.

Community
  • 1
  • 1
saji159
  • 328
  • 7
  • 14
  • As per my understanding you have to re think of logic you are applying while you are doing orientation. – Roll no1 May 08 '12 at 12:10
  • I called the `progressDialog.dismiss()` again in the `onDestroy()` method. During a orientation change, the activity restarts. So before restart we have to destroy the current progressDialog. This does the trick. :D – saji159 May 08 '12 at 14:32
  • Yes... thats i want to communicate – Roll no1 May 09 '12 at 05:19

4 Answers4

1

When you switch orientations, Android will create a new View. You're probably getting crashes because your background thread is trying to change the state on the old one. (It may also be having trouble because your background thread isn't on the UI thread). These are the solutions:

How to handle screen orientation change when progress dialog and background thread active?

Activity restart on rotation Android

Community
  • 1
  • 1
Andrea Motto
  • 1,540
  • 21
  • 38
0

I called the progressDialog.dismiss() in the onDestroy() method.

During a orientation change, the activity restarts. So before restart we have to destroy the current progressDialog. This does the trick. :D

saji159
  • 328
  • 7
  • 14
-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);
    }
Vivek Kumar Srivastava
  • 2,158
  • 1
  • 16
  • 23
-1

I had the same problem and solved it that way that I locked the orientation before start synchronisation and set it back after synchronize:

// before
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

// after synchronisation: 
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92