Android : Broadcast when screen lock appear
<p>I want to run a method when android phones screen lock appear.</p>

<p>I tested <code>ACTION_SCREEN_ON</code> as a broadcast, but it only works when the activity is live.</p>

<p>I also tested <code>ACTION_USER_PRESENT</code> and it works when the phone is unlocked, but I want to run the method before unlocking (just when the screen lock appears).</p>

<p>I also tested <code>AlarmManager</code> by repeating alarm every 1 minute, but this solution has two defects:</p>

<ol>
<li>Battery soon gets empty. </li>
<li>It's a deprecated way, and I don't need to do method every 1 minute.</li>
</ol>

<p>What should I do?</p>