我試圖阻止HOME鍵按鍵響應時服務運行監聽HOME按鈕按下並重新啓動活動
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;
}
但每次當我按下HOME鍵的應用程序崩潰。
你會得到一個錯誤? – 2012-08-07 03:54:48
你可以發佈LOGCAT輸出什麼時候崩潰? – JeffS 2012-08-07 03:55:51