Android get PID of other applications

android, java

Solution

I think you'd need to use ActivityManager: see http://developer.android.com/reference/android/app/ActivityManager.RunningAppProcessInfo.html for the process info. You could:

- Get all running app processes.

- Find your app.

- Get its PID.

Problem

I would like to be able to start an activity or service and get the PID of that process as quickly as possible, immediately would be the best case scenario. Do I have any options other than browsing the /proc directory, which then leads to a variable-amount-of-time race condition between the time the activity/service is launched and the time it takes me to find what I want in the proc directory and begin observing?

Original source

Related problems