Question: I've been trying to use FLAG\_SHOW\_WHEN\_LOCKED and FLAG\_DISMISS\_KEYGUARD to display an activity each time someone turn the screen on. It works well most of the time but there is some case causing strange behaviour. This happens when the activity is already existing and I send it a intent after it has been moved back in the history stack, by using the `Home` button.

First, if I press the `Home` button when on my activity, then switch the screen off and on, the activity is expected to be displayed right away as it was. However what is displayed instead is the basic android lockscreen. My activity is behind.

Worst, sometime, if I touch the home screen, then turn the screen off and on, the home screen overlay (all appli logo and widgets) are displayed with my activity in the background!

The intent I am using each time the screen is turned off to laucn and recall the activity :

```
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
context.startActivity(intent);

```

So, it seems that when my activity is in the history stack, it sometimes does not correctly get recalled and bypass the android lockscreen. Is there something wrong with my intent?

Answer: 
This can be achieved by replacing your asp:Button with the html button and on that button click create an AJAX call to your server function (needs to be marked as WebMethod) then you can exactly follow your requirements

```
1) first disable button on click if all the validation satisfied (like Require filed validator)
2) then call the server side click event of that same button
3) enable that button after executing server side click event

```
I am not sure if your JS code works as you expect, but if the functions work then it should too

```
1) first disable button on click if all the validation satisfied (like Require filed validator)
2) then call the server side click event of that same button

```

You said that the function works but doesn't fire the server function so here you only have to add the `return true;` in your JS function and the server function will be called

```
3) enable that button after executing server side click event

```

In your server side function add this line to call the JS function

```
ScriptManager.RegisterStartupScript(this, this.GetType(), "Funct", "EnableButton();", true);

```

Also, if you are storing the ID of the button to exclusively use it in these two functions, you can leave them like this:

```
function DiableButton(btn) {   
    $(btn).attr("disabled", "disabled");             
    return true;
}

function EnableButton() {
   var btn = $('#<%=btnContinue.ClientID %>').val();
   $(btn).removeAttr("disabled");  
}

```

Hope it helps