-1

I mean I write this code :

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

it is run on sony ,samsung... but it is error on htc phone(wildfire s).Why?

maybe this is reason?

java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:381)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:226)
at android.view.Window$LocalWindowManager.removeView(Window.java:432)
at android.app.Dialog.dismissDialog(Dialog.java:278)
at android.app.Dialog.access$000(Dialog.java:71)
at android.app.Dialog$1.run(Dialog.java:111)
at android.app.Dialog.dismiss(Dialog.java:268)
at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:169)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(Native Method)
CompEng
  • 7,161
  • 16
  • 68
  • 122
  • I do not have logcats :( I do not have that phone. my app run on my phone but htc wildfire s error. 3 persons mail me but not logcat – CompEng Apr 19 '12 at 18:55
  • its hard to help without knowing the problem logs – waqaslam Apr 19 '12 at 18:57
  • "window manager"... I wonder if it's related to HTC Sense? (I only have a Samsung phone, so I can't really help, unfortunately) – Izkata Apr 19 '12 at 19:03
  • It's most likely due to the HTC Sense UI, sometimes it doesn't handle widgets the way that the normal Android UI would. – Jean-Philippe Roy Apr 19 '12 at 19:03

1 Answers1

2

Seems like your activity is not alivevisible when you are setting this flag to its window. Instead, i would suggest you to add the following attribute to any of your view.

android:keepScreenOn="true"

Another reason could be due to orientation change. If you are running an AsyncTask and meanwhile the orientation changes, it actually destroys the activity and recreates it. Now if AsyncTask completes its job, it would try to update the activity which is no longer available and gets crash.

waqaslam
  • 67,549
  • 16
  • 165
  • 178