2012-05-07 69 views
0

我一直在開發通過SensorEventListener使用SensorManager的應用程序。但是有一個問題:當應用程序啓動時,它應該從SensorManager中刪除我的偵聽器並創建一個新的偵聽器,但SensorManager只有兩個方法 - registerListener和unregisterListener,但是當我執行應用程序時,我無法獲取最後一個偵聽器的引用並取消註冊。請告訴我,以便我可以修復它。謝謝。如何從SensorManaget註銷SensorEventListener?

+0

你正在註銷你的聽衆.. –

+0

對不起,我剛剛得到了我的問題的決定。但是現在我有1個問題需要解決 - 我如何獲得所有正在運行的服務才能停止服務? – user1166635

回答

0

不要殺死進程它不是一個好主意。這是檢測服務的代碼。

ActivityManager activity_manager = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE); 
    List<ActivityManager.RunningServiceInfo> current_services = activity_manager.getRunningServices(50); 

    for (int i=0; i<current_services.size(); i++) { 
     ActivityManager.RunningServiceInfo temp_service = current_services.get(i); 
     if (temp_service.getClass().equals("your complete class name with package")) { 
      //DO YOUR WORK HERE. 
      android.os.Process.killProcess(temp_service.pid); //TO KILL PROCESS BUT I RECOMMEND DON'T KILL IT. 
     } 
    }