4
Because that code (Thread
) shows this message (on the compiler), and how to make it not show more?
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 the 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 Soen.
How can I write this code so that it stays correct? Thread executes a command each x seconds if isActive for true.
Attention to question tags.