getWindow().getAttributes()/setAttributes() not working when screen orientation is changed
<p>I was writing a code for screen flashing. Screen flashes repeteadly in some interval so i have done that job on asynctask. Everything is working ok until i change my screen orientation (at runtime i.e i have settings preference in my project also where i can change orientation).
Here is the very rough code:</p>

<pre><code>static WindowManager.LayoutParams lp = MyClass.this.getWindow().getAttributes();
MyClass.lp.screenBrightness = MyClass.brightnessValue / 100.0f;
if(brightnessValue == 100.0f){
MyClass.brightnessValue = 1.0f;
}
else{
MyClass.brightnessValue = 100.0f;
}
handler.sendEmptyMessage(1); //because i can't access this from non ui thread so applying brightness on handler
</code></pre>

<p>//inside handler:</p>

<pre><code>case 1: MyClass.this.getWindow().setAttributes(lp);
break;
</code></pre>

<p>Any idea why code is breaking when orientation is changed</p>

<p>Edit: Ok after testing further i found that its changing brightness is not working after pause. I mean when i close activiity by pressing back and when i run app again screen flashing doesn't work. But if i start new activity and again press back to my main activity then screen flashing works. So my screen flashing is not wrking in 2 scenario:</p>

<blockquote>
  <p>1) When i go back and exit app(i mean when i got to home screen or
  other from my main activity)</p>
  
  <p>2) When i change orientation mode to landscape by starting preference
  activity then i press back and main activity starts in landscape mode.</p>
</blockquote>

<p>Thanks.</p>
