Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art

Determining Whether a Given Application Is Running

Published? true
FormatLanguage: WikiFormat


How do i know if mine or some other app is running?


The system activity manager maintains a list of all active tasks. This provides the name of all running tasks and can be interrogated for various system specific information


This method takes the name of an application and returns true if the ActivityManager thinks it is currently running.

import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;

public boolean isAppRunning (String aApplicationPackageName)
	ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
	if (activityManager == null)
		return false; // should report: can't get Activity Manager
	List<RunningAppProcessInfo> procInfos =
	for(int idx = 0; idx < procInfos.size(); idx++)
			return true;
	return false;