0
我想開發一個任務管理器,比如我想在列表視圖中顯示runnung服務列表和每個服務使用的內存的應用程序。服務使用的內存
我想,可以用
ActivityManager am = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningServiceInfo> procInfos = am.getRunningServices(maxNum);
但如何dislay他們在ListView以及如何獲得由他們每個人所使用的內存來獲得運行的服務? 我是一個機器人初學者,我想任何人都可以解釋我在一個詳細的方式...
我嘗試以下。我可以在logcat中看到服務名稱等,但是申請是強制關閉。
package com.example.ServiceList;
import java.util.List;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.MemoryInfo;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class ServiceListActivity extends Activity {
/** Called when the activity is first created. */
int maxNum = 5;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
this.setContentView(tv);
android.os.Debug.MemoryInfo[] mInfo;
int[] processid = null;
ActivityManager am = (ActivityManager)this.getSystemService (Context.ACTIVITY_SERVICE);
List<RunningServiceInfo> procInfos = am.getRunningServices(maxNum);
for(int i = 0; i < procInfos.size(); i++){
tv.setText(tv.getText().toString()+ " " + "\n");
Log.v("TaskMgr Stringe", procInfos.get(i).service.toString());
Log.v("TaskMgr class name", procInfos.get(i).service.getClassName());
processid[i]=procInfos.get(i).pid;
String s = " "+processid[i];
Log.v("TaskMgr process id",s);
Log.v("TaskMgr process memory", am.getProcessMemoryInfo(processid[0]);
}
mInfo = am.getProcessMemoryInfo(processid);
int dp= mInfo[0].dalvikPss;
String s1= " " + dp;
tv.setText(tv.getText().toString()+ " " + s1);
}
}
Sahiti D,別忘了標記答案! – JoxTraex 2012-02-01 19:15:13
感謝您的答覆..在RunningServicesInfo看到幫助我找到解決方案.. – DSP 2012-02-08 10:05:08