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)

Example:
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 {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  ActivityManager activityManager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
  
  List<ActivityManager.RunningAppProcessInfo> list = activityManager.getRunningAppProcesses();
  
  StringBuilder info = new StringBuilder();
  info.append("lesapplication.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());
  texView.setText(info);
  setContentView(texView);
 }

}


0 Response to "List running application processes of Android device"

Posting Komentar