I'm trying to produce an animation with delay less than 1 milli second.
Based on my research, I found some answers about ScheduledThreadPoolExecutor.
Unfortunately, I applied the following code but it's not working as I expected..
public class MainActivity extends Activity {
ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1);
private Handler mHandler = new Handler();
public void buttonClicked(View v){
if(v.getId() == R.id.start_animation)
{
//Case1
mHandler.post(animateImage);
//Case2
//startEffect();)
}
}
private Runnable animateImage = new Runnable() {
@Override
public void run() {
runOnUiThread(
new Runnable()
{
public void run()
{
doTheAnimation1();
}
});
}
};
private void doTheAnimation1() {
doFlipImage();
}
private void startEffect()
{
long delay = 1000; //the delay between the termination of one execution and the commencement of the next
exec.scheduleAtFixedRate(animateImage, 0, delay, TimeUnit.MICROSECONDS);
}
}
According to the code, once the button is clicked the mHandler will call the animateImage, animateImage will doFlipImage which will create a Bitmap and assign it to the canvas and I start drawing over that canvas, and this bitmap will be used to invalidate an imageview.
if I'm using mHandler then everythings works fine, but if I'm using ScheduledThreadPoolExecutor (so I will call startEffect method instead of mHandler.post), then the imageview appears white after the drawings happened as I guess, How could I solve this issue.