i solved the problem using handler. for any future references, here is the code.
float dim = 0.004f; // if you set this 0, it wont work. 0.004 is the least value
float bright = 1.0f;
Handler mHandler = new Handler();
mHandler.post(new Runnable() {
@Override
public void run() {
lp.screenBrightness= bright;
getWindow().setAttributes(lp);
final Handler handler = new Handler();
Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
lp.screenBrightness=dim;
getWindow().setAttributes(lp);
}
});
}
}, 2000); // flashing of screen
}
});