一个App同时有两个进程:自己的进程和Jpush进程,避免Application执行两次

String currentProcessName = getCurrentProcessName();

if (getPackageName().equals(currentProcessName)) {

onAppCreate();

}
//得到当前进程名
private StringgetCurrentProcessName() {

    String currentProcName ="";

    int pid = android.os.Process.myPid();

    ActivityManager manager = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);

    for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {

    if (processInfo.pid == pid) {

        currentProcName = processInfo.processName;

        break;

    }

}

return currentProcName;

}

你可能感兴趣的:(一个App同时有两个进程:自己的进程和Jpush进程,避免Application执行两次)