android - Determine by which process Application.onCreate() is called -
in application have local service, needs run in separate process. specified as
<service android:name=".myservice" android:process=":myservice"></service>
in androidmanifest.xml. subclass application object , want detect in it's oncreate method when called ordinary launch , when myservice launch. working solution have found described by
https://stackoverflow.com/a/28907058/2289482
but don't want running processes on device , iterate on them. try use getapplicationinfo().processname context, unfortunately return same string, while solution in link above return: mypackage, mypackage:myservice. don't need processname @ first place, solution determine when oncreate method called ordinary launch , when myservice launch. may can done applying kind of tag or label somewhere, didn't find how it.
you can use code process name:
int mypid = android.os.process.mypid(); // process id inputstreamreader reader = null; try { reader = new inputstreamreader( new fileinputstream("/proc/" + mypid + "/cmdline")); stringbuilder processname = new stringbuilder(); int c; while ((c = reader.read()) > 0) { processname.append((char) c); } // processname.tostring() process name! log.v("xxx", "my process name is: " + processname.tostring()); } catch (exception e) { // ignore } { if (reader != null) { try { reader.close(); } catch (exception e) { // ignore } } }
Comments
Post a Comment