サービスの実行中に HOME ボタンの KeyPress を防止しようとしています
protected void onPause () {
if (isMyServiceRunning())
{
Intent Act2Intent = new Intent(PhysicalTheftDialog.this, PhysicalTheftDialog.class);
startActivity(Act2Intent);
}
else {
}
}
private boolean isMyServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if ("nyp.android.project.MyService".equals(service.service.getClassName())) {
return true;
}
}
return false;
}
しかし、ホームボタンを押すたびにアプリケーションがクラッシュします。