sanjana
sanjana

Reputation: 641

Refresh an Activity frequently to update textview android

i am developing an android application where in i have an activity consisting of a text view which is fetching the value from a database every 5 minutes. I want the textview to be updated with the value automatically,each time when the value is fetched. Basically I need to refresh my activity every 5 minutes. I dont want to use

 startActivity(new Intent(Activity.this, Activity.class));
 finish();

Please Help! Thanks!

Upvotes: 0

Views: 1289

Answers (2)

Daniel L.
Daniel L.

Reputation: 5140

When you set the text in a Android TextView it gets refreshed automatically (the setText() method in TextView calls invalidate internally). So you just need to set the text (from the UI thread) whenever you get new value from your DB (a common way for fetching the value from a background thread and then update it from the UI thread is to use Android's AsyncTask).

Upvotes: 3

Arvind Kanjariya
Arvind Kanjariya

Reputation: 2097

At time of fetching value from database. same time execute this below code.

runOnUiThread(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            YOURTEXTVIEW.setText("SET VALUE HERE");
        }
    });

this will update your value.

Upvotes: 1

Related Questions