Jan 10, 2015

List running application processes of Android device

Call getSystemService(ACTIVITY_SERVICE) to get instance of the ActivityManager. With it, your app can interact with the overall activities running in the system. The method getRunningAppProcesses() return a list of application processes that are running on the device. (Note: this method is only intended for debugging or building a user-facing process management UI)

package com.example.androidgetrunning;

import java.util.List;

import android.support.v7.app.ActionBarActivity;
import android.text.method.ScrollingMovementMethod;
import android.app.ActivityManager;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

 protected void onCreate(Bundle savedInstanceState) {
  ActivityManager activityManager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
  List<ActivityManager.RunningAppProcessInfo> list = activityManager.getRunningAppProcesses();
  StringBuilder info = new StringBuilder();
  info.append("android-coding.blogspot.com" + list.size() + "\n\n");
  info.append("no. of running application processes: " + list.size() + "\n");
  for(int i=0; i<list.size(); i++){
   info.append(list.get(i).processName + "\n");
  TextView texView = new TextView(this);
  texView.setMovementMethod(new ScrollingMovementMethod());


No comments:

Post a Comment

Infolinks In Text Ads