//A hodge-podge of tips, snippets, etc. in my journey to figure out the Android thread thing.//
==== Run a routine every second ====
=== With Handler ===
final Handler handler = new Handler();
final int delay = 1000; // 1000 milliseconds == 1 second
handler.postDelayed(new Runnable() {
public void run() {
System.out.println("myHandler: here!"); // Do your work here
handler.postDelayed(this, delay);
}
}, delay);
=== With Timer ===
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
//your method
}
}, 0, 1000);//put here time 1000 milliseconds=1 second
==== Classes and Interfaces ====
Creating an anonymous class:
* Do you have to have an Interface to create the class because it seems to look like this:
InterfaceName instanceName InterfaceName() {
// put your loved ones here;
}
An interface wouldn't take a parameter. If your class needs parameters you'd have a method with the same name as the interface that takes the parameters? I see how this works with classes but not sure with Interfaces
===== References =====
* [[https://guides.codepath.com/android/managing-threads-and-custom-services|Excellent guide to Services]]
===== Not Completely Digested =====
* [[https://developer.android.com/guide/components/services#java|Official documentation of services in Android]]
* [[https://guides.codepath.com/android/Starting-Background-Services|Codepath guide to background services]]
* [[https://developer.android.com/guide/components/processes-and-threads|Official documentation to processes and Threads]]