Android属性系统主要作为跨进程赋值使用。在双虚拟机系统同时运行时,由于属性属于不同的虚拟机,
所以不能使用在异步双虚拟机中。
java:
import android.os.Process;
import android.os.SystemProperties;
int pid = SystemProperties.getInt("runtime.zygoteex.pid", 0);
int ppid = Process.myPPid();
int displayID = 0;
if(pid == ppid) {
displayID = 1;
}
c++:
#include <cutils/properties.h>
char propPid[PROPERTY_VALUE_MAX], propPidex[PROPERTY_VALUE_MAX];
property_get("runtime.zygote.pid", propPid, "");
property_get("runtime.zygoteex.pid", propPidex, "");
if(*propPid != 0 && *propPidex != 0)
{
int ppid = getppid();
if(ppid == atoi(propPid))
{
mDisplay = 0;
gServiceCount = 0;
}
else if(ppid == atoi(propPidex))
{
mDisplay = 1;
gServiceCount = 1;
}
}