refresh datasource on interval

4 posts, 0 answers
  1. Michael
    Michael avatar
    15 posts
    Member since:
    Jun 2015

    Posted 03 Dec 2015 Link to this post

    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);
     });
    });
     

     

     

     

  2. Michael
    Michael avatar
    15 posts
    Member since:
    Jun 2015

    Posted 04 Dec 2015 in reply to Michael Link to this post

    QUESTION 3 : is it a better stratgey to use a background task with plugin? thank you
  3. Tsvetina
    Admin
    Tsvetina avatar
    1876 posts

    Posted 08 Dec 2015 Link to this post

    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.

     
  4. Michael
    Michael avatar
    15 posts
    Member since:
    Jun 2015

    Posted 09 Dec 2015 Link to this post

    Super, thanks a lot :-)
Back to Top