5

I have an Android app that extends the Application class and has many app components (services, activities and broadcast receivers) running along three different process.

Each process will instantiate the Application class as soon as it is started. So I've been looking for how can I check inside the Application class code, if the instance is owned by the main app process but I have not been able to find it anything.

My manifest looks like this:

<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:name=".MyApplication" android:theme="@style/AppTheme" > <activity android:name="..."> ... </activity> <activity android:name="..."> ... </activity> <service android:name="..." > </service> <service android:name="..." android:process=":SecondProcess" > </service> <service android:name="..." android:process=":ThirdProcess" > </service> 

Next is my Application class implementation:

public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); if (is this instance being ran on the main process?) { // Do something } } } 

Does anyone know how to check if the instance is running on the main process?

2
  • 1
    Possible duplicate of Is there a way to get current process name in Android Commented Jan 28, 2016 at 14:43
  • 1
    @Nachi clearly not a duplicate since the focus of both of them is different. One is a mere approach than can be used in the other. Commented Jan 28, 2016 at 17:01

1 Answer 1

0

Looking for the answer for the same question.

So far what i found is use can find the current running process from the process id and put a if check in onCreate.

 public void onCreate(){ ... String processName = getProcessName(); switch(processName){ case process1: // do something break; case process2: // do something break; .... } 
Sign up to request clarification or add additional context in comments.

2 Comments

There is no getProcessName() method on the Application class.
yes there is no direct method but you can find the process name.. check this stackoverflow.com/questions/19631894/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.