Nargis
Nargis

Reputation: 4787

Refreshing Data from Server

I am designing a TV Guide Application for Android. It will access the Server through the HTTP:GET Request and provide the program details through an XML.

Because data is dynamic, I have to keep refreshing it.I will be storing data in a datastructure like ArrayList and not in sqlite database.

My questions is how to refresh data .I thought of refreshing data every 30 mins but it does not seem efficient.

Any other way? Can a Sync Adapter be helpful here?

Upvotes: 0

Views: 125

Answers (1)

Chirag
Chirag

Reputation: 56925

You have to use a Handler and its postDelayed method to invalidate the list's adapter as follows:

    Handler handler = new Handler()
    handler.postDelayed( new Runnable() 
   {
        @Override
        public void run() 
         {
            // Call Webservice fetchdata and stored into arraylist and notifydataset
            adapter.notifyDataSetChanged();
            handler.postDelayed( this, 60 * 1000 );
         }
    }, 60 * 1000 );

Here the above code works after every 1 minutes . You need to change time according to your requirement.

Upvotes: 2

Related Questions