In Eclipse, I found that using a TimeLine and a KeyFrame I can delay the execution of code, for example, to wait 4 seconds before playing a media I used this code:
Timeline timeline = new Timeline();
KeyFrame keyframe = new KeyFrame(Duration.millis(4000), DelayAnimation ->
{
GeneralMethods PlayMusic = new GeneralMethods();
PlayMusic.playMusic(mediaPlayer);
});
timeline.getKeyFrames().add(keyframe);
timeline.play();
The previous code works fine in Eclipse and I did not need to create a new thread.
My question is, Is there a similar way to delay the execution of code in Android?
I found a way to delay the execution of code, but it is using a handler, that is to say, creating a new thread. I would like to delay without using a thread, is it possible?