android android - 1 year ago 147
Android Question

How can I create timer tick in Android?

I have this method

public void GetSMS(){
//in this method I read SMS in my app inbox,
//If have new SMS create notification

for this I think create timer tick method and every 5 sec call GetSMS()

How can I create a correct method for that ?

Answer Source

Here is an example of Timer and Timer Task. Hope this helps.

final Handler handler = new Handler();
Timer timer = new Timer(false);
TimerTask timerTask = new TimerTask() {
    public void run() { Runnable() {
            public void run() {
                // Do whatever you want
timer.schedule(timerTask, 1000); // 1000 = 1 second.