This is a migrated thread and some comments may be shown as answers.

refresh datasource on interval

3 Answers 119 Views
HTML5, CSS, JavaScript
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michael
Top achievements
Rank 1
Michael asked on 03 Dec 2015, 07:29 PM

Hello,
I want my app content to be often up to date.
So i plan to read my datasource :

  • obviously when the app is launched (we dont need to talk about that) 
  • + every time my user resume to the app after leaving it more then 10 seconds
  • + every 10 seconds when my user is in the app

QUESTION 1 : i looked for code do that in the kendo ui mobile documentation but didnt find anything. did i miss something?

QUESTION 2 : I made this code that seem to work like magic, is it the right strategy?
(i obviously dont want my app to make to many calls to telerik backend and slow down or crash)

 thank you

document.addEventListener('deviceready', function() {
 (function poll(){
       setTimeout(function(){
          dataSource.read().then(
            function(){
                poll();
            }
          );
      }, 10000);
 });
});
 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 1
answered on 04 Dec 2015, 09:35 AM
QUESTION 3 : is it a better stratgey to use a background task with plugin? thank you
0
Tsvetina
Telerik team
answered on 08 Dec 2015, 02:30 PM
Hi Michael,

You can use the Cordova onPause and onResume events to achieve your first task (refresh data on app resume). If you need to check the length of time that has passed while the app was suspended, you can get the time in milliseconds on pause and then get it on resume and compare the two values to determine what period of time has passed.

As for refreshing the DataSource on a 10 seconds interval, this sounds a bit too often, as it would cause flashing of the data and the users may not be able to view the data effectively. You can either use a longer period of time (note that setInterval is more appropriate than setTimeout for repeating actions), or give up automatic updates and let the user trigger updates when they want them:
Pull to refresh

Regards,
Tsvetina
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
0
Michael
Top achievements
Rank 1
answered on 09 Dec 2015, 09:57 AM
Super, thanks a lot :-)
Tags
HTML5, CSS, JavaScript
Asked by
Michael
Top achievements
Rank 1
Answers by
Michael
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or