Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This file contain a thread as class that run a log every 3 seconds
// [ES] Hilo dormilón
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class ThreadSleepyheadIndependentClass extends AppCompatActivity {
TextView texto;
Button boton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
texto = (TextView) findViewById(R.id.texto);
boton = (Button) findViewById(R.id.boton);
boton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Hilo hilo = new Hilo();
hilo.start();
}
});
}
public class Hilo extends Thread {
public void run(){
for(int i =1; i<= 10; i++){
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Log.d("DEBUG", String.valueOf(i)); //This runs every 3 seconds
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.