0

I've got a full screen, portrait activity as defined below.

In manifest:

<activity 
    android:name=".CameraActivity"
    android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
</activity>

and

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

The OnCreate method of this activity simply invokes an alert box with, YES and NO buttons. My problem is that when the phone is kept in landscape the alert box crashes and I get the leaked window error displayed below.

12-06 15:26:01.590: E/WindowManager(6286): Activity com.eyepax.rdms.CameraActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4058c508 that was originally added here
12-06 15:26:01.590: E/WindowManager(6286): android.view.WindowLeaked: Activity com.eyepax.rdms.CameraActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4058c508 that was originally added here
12-06 15:26:01.590: E/WindowManager(6286):  at android.view.ViewRoot.<init>(ViewRoot.java:277)
12-06 15:26:01.590: E/WindowManager(6286):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
12-06 15:26:01.590: E/WindowManager(6286):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
12-06 15:26:01.590: E/WindowManager(6286):  at android.view.Window$LocalWindowManager.addView(Window.java:433)
12-06 15:26:01.590: E/WindowManager(6286):  at android.app.Dialog.show(Dialog.java:288)
12-06 15:26:01.590: E/WindowManager(6286):  at com.eyepax.rdms.CameraActivity$CameraTask.onPreExecute(CameraActivity.java:177)
12-06 15:26:01.590: E/WindowManager(6286):  at android.os.AsyncTask.execute(AsyncTask.java:391)
12-06 15:26:01.590: E/WindowManager(6286):  at com.eyepax.rdms.CameraActivity.onActivityResult(CameraActivity.java:127)
12-06 15:26:01.590: E/WindowManager(6286):  at android.app.Activity.dispatchActivityResult(Activity.java:4094)
12-06 15:26:01.590: E/WindowManager(6286):  at android.app.ActivityThread.deliverResults(ActivityThread.java:2905)
12-06 15:26:01.590: E/WindowManager(6286):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2436)
12-06 15:26:01.590: E/WindowManager(6286):  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2481)
12-06 15:26:01.590: E/WindowManager(6286):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1847)
12-06 15:26:01.590: E/WindowManager(6286):  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3288)
12-06 15:26:01.590: E/WindowManager(6286):  at android.app.ActivityThread.access$1600(ActivityThread.java:132)
12-06 15:26:01.590: E/WindowManager(6286):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1042)
12-06 15:26:01.590: E/WindowManager(6286):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-06 15:26:01.590: E/WindowManager(6286):  at android.os.Looper.loop(Looper.java:143)
12-06 15:26:01.590: E/WindowManager(6286):  at android.app.ActivityThread.main(ActivityThread.java:4268)
12-06 15:26:01.590: E/WindowManager(6286):  at java.lang.reflect.Method.invokeNative(Native Method)
12-06 15:26:01.590: E/WindowManager(6286):  at java.lang.reflect.Method.invoke(Method.java:507)
12-06 15:26:01.590: E/WindowManager(6286):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-06 15:26:01.590: E/WindowManager(6286):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-06 15:26:01.590: E/WindowManager(6286):  at dalvik.system.NativeStart.main(Native Method)
Tobbe
  • 1,825
  • 3
  • 21
  • 37
Jay Mayu
  • 17,023
  • 32
  • 114
  • 148

1 Answers1

3

Its because the activity will be recreated when the device is turned to LANDSCAPE mode. So it is throwing window bad token.

Just try adding the following lines of code in your manifest.

android:configChanges="keyboardHidden|orientation"
Hussain
  • 5,552
  • 4
  • 40
  • 50
  • This should not be used because of various issues. Android sdk site says "Note: Handling the configuration change yourself can make it much more difficult to use alternative resources, because the system does not automatically apply them for you. This technique should be considered a last resort when you must avoid restarts due to a configuration change and is not recommended for most applications." – rfsk2010 Dec 06 '11 at 10:11
  • Please take a look at this answer: http://stackoverflow.com/questions/456211/activity-restart-on-rotation-android – Hussain Dec 06 '11 at 10:15
  • Please have a look here as well, in case you havent http://developer.android.com/guide/topics/resources/runtime-changes.html – rfsk2010 Dec 06 '11 at 10:17