我需要同时运行两个进程。我写了代码:
public void starttwoprocessing () {
final Thread tworunprocessing = new Thread(new Runnable() {
public void run() {
FlashLight.onFlashResume();
handler.post(new Runnable() {
public void run() {
camera.takePicture(null, null, photoCallback);
}
});
}
});
tworunprocessing.start();
}
第一次开始:
camera.takePicture(null, null, photoCallback);
第二:
FlashLight.onFlashResume();
换个地方后结果一样。在这种情况下,我得到了第一张照片,然后闪光开始了。
Thread.sleep(...);
没有帮助
如何同时启动闪光灯,并立即拍照?谢谢
像这样写:
public class Launcher
{
public void main(String args[]) throws IOException, InterruptedException
{
try {
Process[] proc = new Process[2];
proc[0] = new ProcessBuilder("FlashPreview.onFlashResumeStart()").start();
Thread.sleep(3000);
proc[1] = new ProcessBuilder("camera.takePicture(null, null, photoCallback)").start();
try {
Thread.sleep(3000);
}
catch (InterruptedException ex)
{
}
proc[0].destroy();
Thread.sleep(3000);
proc[1].destroy();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
称为:
mk = new Launcher();
try {
mk.main(null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我做错了什么。根本不起作用,没有崩溃,但在日志中写道:07-05 16:38:58.217: W/System.err(30934): java.io.IOException: Error running exec()。命令:[FlashPreview.onFlashResumeStart()] 工作目录:null 环境:[ANDROID_SOCKET_zygote=9, SECONDARY_STORAGE=/storage/extSdCard:/storage/UsbDriveA:/storage/UsbDriveB:/storage/UsbDriveC:/storage/UsbDriveD:/storage/ UsbDriveE:/storage/UsbDriveF, ANDROID_BOOTLOGO=1, EXTERNAL_STORAGE=/storage/sdcard0, ANDROID_ASSETS=/system/app, PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin, ASEC_MOUNTPOINT=/mnt/asec, LOOP_MOUNTPOINT=/mnt/obb, BOOTCLASSPATH=/system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ ext.jar:/system/framework/framework.jar:/system/framework/framework2.jar:/system/framework/framework_ext。