Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get current process name in Android

Tags:

android

I set an Android:process=":XX" for my particular activity to make it run in a separate process. However when the new activity/process init, it will call my Application:onCreate() which contains some application level initialization.

I'm thinking of avoiding duplication initialization by checking current process name.

So is there an API available?

Thanks.

like image 363
Rick Li Avatar asked Oct 28 '13 10:10

Rick Li


People also ask

How do I find Android processes?

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 Android process death?

Your Android application (process) can be killed at any time if it's in paused or stopped state . The state of your Activities, Fragments and Views will be saved.

What is process management Android?

Android Automatically Manages Processes When Android needs more system resources, it will start killing the least important processes first. Android will start to kill empty and background processes to free up memory if you're running low.

What is process in Android application?

A process is considered to be in the foreground if any of the following conditions hold: It is running an Activity at the top of the screen that the user is interacting with (its onResume() method has been called). It has a BroadcastReceiver that is currently running (its BroadcastReceiver.


1 Answers

Full code is

    String currentProcName = "";     int pid = android.os.Process.myPid();     ActivityManager manager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);     for (RunningAppProcessInfo processInfo : manager.getRunningAppProcesses())     {         if (processInfo.pid == pid)         {             currentProcName = processInfo.processName;             return;         }     } 
like image 148
Rick Li Avatar answered Oct 02 '22 20:10

Rick Li