Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory used by a service
    primarykey
    data
    text
    <p>I want to develop a task manager like application where I want to display the list of runnung services and the memory used by each service in a list view.</p> <p>I figured that running services can be obtained using</p> <pre><code>ActivityManager am = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE); List&lt;RunningServiceInfo&gt; procInfos = am.getRunningServices(maxNum); </code></pre> <p>But how to dislay them in a ListView and also how to obtain the memory used by each one of them? I am an android beginner and I wish anyone could explain me in a detailed manner...</p> <p>I tried the following. I could see the service name etc in logcat but the apllication is force closing.</p> <pre><code> 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&lt;RunningServiceInfo&gt; procInfos = am.getRunningServices(maxNum); for(int i = 0; i &lt; 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 ); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload