Skip to content

Instantly share code, notes, and snippets.

@truedem
Created September 11, 2016 17:54
Show Gist options
  • Select an option

  • Save truedem/804401024f470c9749b9ba240092748a to your computer and use it in GitHub Desktop.

Select an option

Save truedem/804401024f470c9749b9ba240092748a to your computer and use it in GitHub Desktop.
Check if an app is running in Android
// packageName = "com.example.yourapp"
public Boolean isAppRunning(String packageName) {
ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); // this = context
List<RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
for(int i = 0; i < procInfos.size(); i++) {
if(procInfos.get(i).processName.equals(packageName)) {
// Toast.makeText(getApplicationContext(), "App " + packageName + " is running", Toast.LENGTH_LONG).show();
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment