I will show sample code how to create repeated a task with a time delay in android programmatically.
Please try it yourself
package com.j4android;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
PopupWindow popupWindow;
@Override
public void onCreate(Bundle bundle){
super.onCreate(bundle);
setContentView(R.layout.main);
repeatedCallMethod();
}
public void repeatedCallMethod() {
TimerTask repeatedProcess;
final Handler handler = new Handler();
Timer timer = new Timer();
repeatedProcess = new TimerTask() {
int count = 0;
@Override
public void run() {
handler.post(new Runnable() {
public void run() {
try {
System.out.println("Process" + count);
count++;
} catch (Exception e) {
}
}
});
}
};
timer.schedule(repeatedProcess, 0, 5000);
}
}
Please try it yourself
package com.j4android;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
PopupWindow popupWindow;
@Override
public void onCreate(Bundle bundle){
super.onCreate(bundle);
setContentView(R.layout.main);
repeatedCallMethod();
}
public void repeatedCallMethod() {
TimerTask repeatedProcess;
final Handler handler = new Handler();
Timer timer = new Timer();
repeatedProcess = new TimerTask() {
int count = 0;
@Override
public void run() {
handler.post(new Runnable() {
public void run() {
try {
System.out.println("Process" + count);
count++;
} catch (Exception e) {
}
}
});
}
};
timer.schedule(repeatedProcess, 0, 5000);
}
}