Skip to content

Instantly share code, notes, and snippets.

@aldakur
Last active July 15, 2016 09:35
Show Gist options
  • Save aldakur/4eb3dacc6279f8834f4e9b0e041ceec1 to your computer and use it in GitHub Desktop.
Save aldakur/4eb3dacc6279f8834f4e9b0e041ceec1 to your computer and use it in GitHub Desktop.
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