Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: determinine my app's process ID? [duplicate]

Tags:

java

android

pid

Is there a way within a java app that's running under Android to determine that app's process ID ("PID")?

The reason I want this is that I am writing an app which reads and processes lines from logcat, and I want to be able to ignore all logcat lines that have been written by this app, itself.

I know I can do this by using a unique tag for my app in all the Log.*() calls and then ignoring logcat lines with this tag, but it seems to me that it would be cleaner if I could simply ignore all logcat lines which have been written by my own app's PID.

I've searched, but I couldn't find anything which explains how to determine the PID of a running Android app, from within that app, itself.

Thanks in advance for any suggestions or pointers to docs.

like image 576
HippoMan Avatar asked Sep 21 '14 20:09

HippoMan


People also ask

Can one Android application have multiple processes?

However, you can arrange for different components in your application to run in separate processes, and you can create additional threads for any process. This document discusses how processes and threads work in an Android application.

What is PID in app?

What I understand is that PID is a unique process ID for each running application. Can an application have more than one PID running at the same time and how can we see that from the strace output? android. system-calls. pid.

How do I find out what processes are running on my Android?

The ability to view running processes in Android is found in the Developer Options. In order to do that, open the Settings app and locate About Phone. In the About Phone section, locate Build Number (Figure A). The Build Number of your device lists the date your version of Android was built.

What is multi process in Android?

As your app grows, you might find it useful to place some of your app components in a process other than your app's main process. To test app components in these non-default processes, you can use the functionality of Multiprocess Espresso.


1 Answers

You're looking for this, I think:

int id = android.os.Process.myPid(); 
like image 130
Ted Hopp Avatar answered Sep 19 '22 18:09

Ted Hopp