Use timertask to update clock each X seconds?
<p>I'm trying to update my digital clock using timertask. I have created a function called updateClock() which sets the hours and minutes to the current time but I haven't been able to get it to run periodically. From what I've read in other answers one of the best options is to use timertask however I haven't been able to make any example I found online work inside an Android activity.</p>

<p>This is what I've written so far:</p>

<pre><code>public class MainActivity extends Activity {
    TextView hours;
    TextView minutes;
    Calendar c;
    int cur_hours;
    int cur_minutes;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.clock_home);
        hours = (TextView) findViewById(R.id.hours);
        minutes = (TextView) findViewById(R.id.minutes);
        updateClock();
        }

    public void updateClock() {
        c = Calendar.getInstance();
        hours.setText("" + c.get(Calendar.HOUR));
        minutes.setText("" + c.get(Calendar.MINUTE));
        }

    public static void init() throws Exception {
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
            public void run() {
                    updateClock(); // ERROR
                }
            }, 0, 1 * 5000);
        }
    }
</code></pre>

<p>How can I make it work?</p>
