在Android中 獲取正在運行的Service 實例
更新時間:2013年04月19日 16:15:21 作者:
本篇文章小編為大家介紹,在Android中 獲取正在運行的Service 實例。需要的朋友參考下
public class ServiceList extends Activity {
@Override
protected 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);// 從窗口管理器中獲取正在運行的Service
tv.setText(getServicesName(serviceList));
setContentView(tv);
}
private boolean ServiceIsStart(List<ActivityManager.RunningServiceInfo> list, String className) {// 判斷某個服務(wù)是否啟動
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) {// 獲取所有服務(wù)的名稱
String res = "";
for (int i = 0; i < list.size(); i++) {
res += list.get(i).service.getClassName() + "/n";
}
return res;
}
}
相關(guān)文章
Android自定義有限制區(qū)域圖例角度自識別涂鴉工具類
這篇文章主要為大家介紹了Android自定義有限制區(qū)域圖例角度自識別涂鴉工具類,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-02-02
Android啟動頁用戶相關(guān)政策彈框的實現(xiàn)代碼
這篇文章主要介紹了Android啟動頁用戶相關(guān)政策彈框的實現(xiàn)方法,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-05-05
Android編程實現(xiàn)帶有圖標的ListView并帶有長按菜單效果示例
這篇文章主要介紹了Android編程實現(xiàn)帶有圖標的ListView并帶有長按菜單效果,結(jié)合實例形式分析了Android帶圖標的ListView及菜單功能相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2017-06-06
Android React Native原生模塊與JS模塊通信的方法總結(jié)
這篇文章主要介紹了Android React Native原生模塊與JS模塊通信的方法總結(jié)的相關(guān)資料,需要的朋友可以參考下2017-02-02
詳解Android Studio安裝ButterKnife插件(手動安裝)
這篇文章主要介紹了詳解AndroidStudio安裝ButterKnife插件(手動安裝),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-08-08
Retrofit自定義請求參數(shù)注解的實現(xiàn)思路
這篇文章主要給大家介紹了Retrofit自定義請求參數(shù)注解的實現(xiàn)思路,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-12-12

