Skip to content Skip to sidebar Skip to footer

Error Updating Textview From Timertask's Run Method

I'm trying to test UI and Timer class possibilities. So I tried the following exercise: === TestTimerActivity.java === package com.tvt.TestTimer; import android.app.Activity; impo

Solution 1:

Do that UpateTime() operation on the UI thread.

protectedvoidUpdateTime() 
{
     runOnUiThread(new Runnable() 
     {
    publicvoidrun() 
    {
            _tv.setText( "" + _count );
        }
     });
}

Hopefully resolves your problem.

Solution 2:

Updating the UI from a thread other than the UI/main thread will fail as Android does not allow it. Try using a Handler to post messages back to the UI thread.

Or maybe try using AsyncTask which presents a set of really simple callback methods to handle the worker and UI threads. But that might not be exactly what you need since you're trying to test out the TimerTask class.

Post a Comment for "Error Updating Textview From Timertask's Run Method"