I'm running a remote service and an application in the main process. I have 
named my process in the manifest :remote for example. When I launch my 
application, it instantiates an app for both processes the main and service 
process(:remote). However inside the onCreate for my application, 
processName is the same in both cases, com.example.exampleapp, instead of 
com.example.exampleapp and com.example.exampleapp:remote. At the very 
bottom, I've attached a workaround to know this, but it's at best ugly, if 
I get all the running processes and search for mine, then I check the 
service pid I can know whether I'm inside the service or not by comparing 
to myPid(). There are other hacks as well like checking inside the binder 
if calling pid is equal to myPid().

Is there an easier way to know of the remote process? Maybe we could also 
get processName fixed?

<service android:enabled="true" 
android:exported="false"
android:process=":remote" 
android:name=".service.MyService">

///// Code
public class MyApplication extends Application {

@Override 
public void onCreate() {
   super.onCreate(); 
   Log.i("test", this.getApplicationInfo().processName);
}

//Nasty workaround.
import android.app.ActivityManager; 
import android.app.ActivityManager.RunningAppProcessInfo; 
import android.content.Context; 
import android.util.Log; 
import android.os.Process; 

public class ProcessUtil { 

private static final String remoteProcess = 
"com.example.exampleapp:remote"; 

public static boolean isRemoteProcess(Context context){ 
  ActivityManager manager = (ActivityManager) 
context.getSystemService(Context.ACTIVITY_SERVICE); 
    for (RunningAppProcessInfo process : manager.getRunningAppProcesses()) 
{ 
      if (remoteProcess.equals(process.processName)) { 
        return Process.myPid() == process.pid; 
      } 
    } 

    return false; 
  } 
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to