why when i call thread.start(); after thread.interrupt(); it gives me exception Thread already started. and app stop on samsung device with android 4.1.2 and doesn't give me that exception and app work normal on lenovo device with android 7 while it is the same code ??? it is a code to make flashlight blinker when i start the blinker then stop it and try to start again .. it stop on a device and work well on another device.
`
//thread blinker
final Thread blinker = new Thread() {
public void run() {
while (!this.isInterrupted()) {
try {
if (myCamera == null) {
try {
myCamera = Camera.open();
} catch (RuntimeException e) {
}
}
final Parameters p = myCamera.getParameters();
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
myCamera.setParameters(p);
myCamera.startPreview();
Thread.sleep(150);
p.setFlashMode(Parameters.FLASH_MODE_OFF);
myCamera.setParameters(p);
myCamera.stopPreview();
Thread.sleep(150);
} catch (InterruptedException e) {
final Parameters p = myCamera.getParameters();
p.setFlashMode(Parameters.FLASH_MODE_OFF);
myCamera.setParameters(p);
myCamera.stopPreview();
Thread.currentThread().interrupt();
}
}
}
};
//on button
final Button onButton = findViewById(id.on);
onButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
blinker.start();
}
});
//off button
final Button offButton = findViewById(id.off);
offButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
blinker.interrupt();
}
});
` when i add blinker.join(); with .interrupt(); it also gives me the same exception ... i'm new to java and i hope my question is not repeated