4\u3001Application\u4f1a\u88ab\u521b\u5efa\u591a\u6b21<\/strong><\/span><\/div>\n\u5f53\u4e00\u4e2a\u7ec4\u4ef6\u8dd1\u5728\u4e00\u4e2a\u65b0\u7684\u8fdb\u7a0b\u4e2d\u65f6\uff0c\u7cfb\u7edf\u7ed9\u65b0\u7684\u8fdb\u7a0b\u5206\u914d\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u673a\uff0c\u5c31\u76f8\u5f53\u4e8e\u5e94\u7528\u53c8\u4e00\u6b21\u7684\u91cd\u65b0\u542f\u52a8\uff0cApplication\u4f5c\u4e3a\u5e94\u7528\u57fa\u7840\u80af\u5b9a\u4e5f\u4f1a\u88ab\u91cd\u65b0\u521b\u5efa;<\/p>\n
\u65b0\u5efaApplication\u7c7b\uff0c\u7ee7\u627f\u81eaApplication\uff0c\u5e76\u5728onCreate\u65b9\u6cd5\u4e2d\u8f93\u51fa\u5f53\u524d\u8fdb\u7a0b\u7684PID\uff1a<\/p>\n
public class LApplication extends Application { \r\n private static final String TAG = \"LApplication\"; \r\n @Override \r\n public void onCreate() { \r\n super.onCreate(); \r\n Log.e(TAG, \"onCreate: \" + android.os.Process.myPid()); \r\n } \r\n}<\/pre>\n\u5f53\u4f9d\u6b21\u5f00\u542f\u8fdb\u7a0b\u540e\u8f93\u51fa\u5982\u4e0b\uff1a<\/p>\n
\/\/ Main \r\nE\/LApplication: onCreate: 16031 \r\n\/\/ RemoteActivity1 \r\nE\/LApplication: onCreate: 16127 \r\n\/\/ RemoteActivity2 \r\nE\/LApplication: onCreate: 16202<\/pre>\nApplication\u88ab\u521b\u5efa\u591a\u6b21\u5e26\u6765\u7684\u95ee\u9898\u662f\uff0c\u6709\u4e9b\u65f6\u5019\u4f1a\u9700\u8981\u5728Application\u4e2d\u521d\u59cb\u5316\u4e9b\u4f9d\u8d56\uff0c\u4f46\u662f\u591a\u8fdb\u7a0b\u5c31\u4f1a\u968f\u7740Application\u7684\u521b\u5efa\u800c\u91cd\u590d\u521d\u59cb\u5316\uff0c\u53ef\u4ee5\u5728Application\u4e2d\u8bbe\u7f6e\u4e00\u4e9b\u6761\u4ef6\u8df3\u8fc7\u91cd\u590d\u521d\u59cb\u5316\u90e8\u5206;<\/p>\n
\/\/ \u6839\u636epid\u83b7\u53d6\u8fdb\u7a0b\u540d \r\nprivate String getAppName(int pid) { \r\n String processName = null; \r\n ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); \r\n List list = am.getRunningAppProcesses(); \r\n for (ActivityManager.RunningAppProcessInfo info : list) { \r\n try { \r\n if (info.pid == pid) { \r\n processName = info.processName; \r\n return processName; \r\n } \r\n } catch (Exception e) { \r\n e.printStackTrace(); \r\n return null; \r\n } \r\n } \r\n return null; \r\n}<\/pre>\n\u901a\u8fc7PID\u83b7\u53d6\u8fdb\u7a0b\u540d\uff0c\u4e0e\u5305\u540d\u505a\u5bf9\u6bd4\uff0c\u53ea\u6709\u8ddf\u5305\u540d\u4e00\u81f4\u65f6\u624d\u505a\u4e00\u4e9b\u521d\u59cb\u5316\u5de5\u4f5c;<\/p>\n","protected":false},"excerpt":{"rendered":"
Android\u7684\u591a\u8fdb\u7a0b\u901a\u4fe1\u5373IPC\u662f\u6307\u4e24\u4e2a\u8fdb\u7a0b\u4e4b\u95f4\u8fdb\u884c\u6570\u636e\u4ea4\u6362; \u8fdb\u7a0b\u4e00\u822c\u6307\u4e00\u4e2a\u6267\u884c\u5355\u5143\uff0c\u5728PC\u548c\u79fb\u52a8\u8bbe\u5907\u4e2d\u6307 […]<\/p>\n","protected":false},"author":1329,"featured_media":230000,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-229993","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/229993","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1329"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=229993"}],"version-history":[{"count":6,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/229993\/revisions"}],"predecessor-version":[{"id":230001,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/229993\/revisions\/230001"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/230000"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=229993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=229993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=229993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}