Closed yyzhuang closed 9 years ago
To check if there's an sl4a process running, we can use the code from this page
private boolean isMyServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if ("com.googlecode.android_scripting.activity.ScriptingLayerService"
.equals(service.service.getClassName())) {
return true;
}
}
return false;
}
When SensibilityTestbed app starts up, it spawns a JSON RPC server via SL4A so we can interface the device's sensors. If you restart the app (by pressing stop/start in the main screen), it blindly spawns another server. It doesn't check whether a prior server instance exists. This behavior is evidenced by the increasing number of running scripts indicated in the SL4A status icon when we restart SensibilityTestbed. In my tests, ten or so servers didn't cause resource shortages, so the problem seems to be more cosmetic. However, we should obviously reuse an existing server instance rather than creating a new one each time we restart; alternatively, we should stop the running server instance when our nodemanager and softwareupdater are stopped.