public class ServiceList extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);TextView tv = new TextView(this);
ActivityManager activityManger = (ActivityManager) getSystemService(ACTIVITY_SERVICE);// 擷取Activity管理器List<ActivityManager.RunningServiceInfo> serviceList = activityManger.getRunningServices(30);// 從視窗管理器中擷取正在啟動並執行Servicetv.setText(getServicesName(serviceList));setContentView(tv);}private boolean ServiceIsStart(List<ActivityManager.RunningServiceInfo> list, String className) {// 判斷某個服務是否啟動for (int i = 0; i < list.size(); i++) {if (className.equals(list.get(i).service.getClassName()))return true;}return false;}private String getServicesName(List<ActivityManager.RunningServiceInfo> list) {// 擷取所有服務的名稱String res = "";for (int i = 0; i < list.size(); i++) {res += list.get(i).service.getClassName() + "/n";}return res;}}