Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android get PID of other applications

Tags:

java

android

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?

like image 475
MattC Avatar asked May 18 '11 02:05

MattC


People also ask

How do I get the PID of my running app?

In the Start menu search bar, search for command prompt and select Run as administrator. Type tasklist. Press Enter. Command Prompt will now display the PID for the running processes.

What is startForeground in Android?

A started service can use the startForeground(int, android. app. Notification) API to put the service in a foreground state, where the system considers it to be something the user is actively aware of and thus not a candidate for killing when low on memory.

What is PID Android?

pid = process ID. uid = user ID of the application that owns that process. gid = group IDs of the application that owns that process.


1 Answers

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:

  1. Get all running app processes.
  2. Find your app.
  3. Get its PID.
like image 161
Femi Avatar answered Nov 21 '22 15:11

Femi