Press home button to stop service
<p>i want to if the user press home button my service will be stop , this is my code but it's not working for me, please help me:</p>

<pre><code>@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_HOME) {
stopService(new Intent(this, MyService.class));
return true;
}
return super.onKeyDown(keyCode, event);
}
</code></pre>

<p>Thanks</p>
