I have write the following code in the onCreate() method of Activity class
Button btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
WindowManager.LayoutParams params = getWindow().getAttributes();
params.screenBrightness = 0;
getWindow().setAttributes(params);
Toast.makeText(v.getContext(),"Button Clicked",Toast.LENGTH_LONG).show();
}
});
btn.performClick();
But the problem is that the action on the button click is not happened, but if I click on that button then this action is performed.
I want to lock the screen by using that code, but it locks after the full execution of onCreate() method,
Any guess how i can do this.
try this