Because this code ( Thread
) shows this message ( in the compiler ), and how do you not show it again?
Code:
public void onCreate(Bundle icicle) {
...
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mediaPlayer) {
(new Thread(new Runnable() { //(Anonymous new Runnable() can be replaced with lambda)
@Override
public void run() {
while (!Thread.interrupted() && isActive)
try {
Thread.sleep(5000);
runOnUiThread(new Runnable() //(Anonymous new Runnable() can be replaced with lambda)// start actions in UI thread
{
@Override
public void run() {
Log.v("INFOS: THREAD", "Valor atribuido"); // this action have to be in UI thread
}
});
} catch (InterruptedException e) {
// ooops
}
}
})).start(); // the while thread will start in BG thread
}
});
}
Message in compiler:
Anonymous new Runnable () can be replaced with lambda less ... (Ctrl + F1) This inspection reports all anonymous classes which can be replaced with Lambda expressions Lambda syntax is not supported under Java 1.7 or earlier JVMs.
Reference in the SOen .
How can I write this code so that it is correct ? The thread executes a command every x seconds if isActive true .
Attention to the question tags.