Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Background App Refresh PhoneGap

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Background App Refresh PhoneGap

    I am curious if anyone has had luck getting background refresh to work with phone gap and alpha? I came across the plugin at the link below and added it to my phone gap builder and everything seems to build correctly (can get the test app on my device using the QR code), but I can't seem to get the background refresh to fire (essentially I open my app to a list and then go make a change to that lists data on the desktops side and stay out of the app for a prolonged period of time (over 30 minutes to be safe) and then open it to see if the background refresh ran.

    https://github.com/transistorsoft/co...ckground-fetch

    #2
    Re: Background App Refresh PhoneGap

    Just wanted to re-open this to see if anyone else has gotten this to work. Here are the updated links to some plugins on GitHub, not sure if there are others, these are just the two main ones I have found in my searching. Also, curious if anyone has attempted background refreshes of list data using the geolocation plugin (haven't looked into the code for this but figured if it is allowed to run in the background then there may be a way to refresh my list data using this). Hopefully I'm not the only one trying to implement this!

    https://github.com/katzer/cordova-pl...ackground-mode


    https://github.com/transistorsoft/co...ckground-fetch

    Comment


      #3
      Re: Background App Refresh PhoneGap

      I'm not seeing an issue with this... using the cordova-plugin-background-fetch plugin @ version 5.3.0. I'm testing with Android.

      What code do you have running in the fetchCallback function?

      I created an app with just a List and left the default interval at 15 mins. I installed that app at 1pm and went out. 2 hours later the fetchCallback function had fired 8 times... and my List now includes the changes I made to the table after the app was installed.

      Comment


        #4
        Re: Background App Refresh PhoneGap

        I am looking for a solution on both Android and iOS, I haven't attempted either one of these plugins recently, gave up on them when I originally tried to do this back in 2016 and just haven't had an opportunity to sit back down and attempt. The code I would be running in my fetchCallback would just refresh the multiple lists I have in the component to make sure changes on the backend don't affect the users. Would be interested to see what code you have set up in the client side actions to get this to run if you don't mind sharing? Also, did you add the plugin manually by editing the config.xml file or did you add it through the phone gap builder within Alpha Anywhere (I used the latter approach the last time I tried so maybe this is why it never worked properly because I didn't set it up right).

        Comment


          #5
          Re: Background App Refresh PhoneGap

          Standard sample code taken from the plugin doc... running in the UX Client-side event - onPhoneGapReady...

          Code:
          var BackgroundFetch = window.BackgroundFetch;
          
          // Your background-fetch handler.
          var fetchCallback = function() {
          	console.log('[js] BackgroundFetch event received');
          	{dialog.object}.refreshListData('LISTCLIENT');
          	// Required: Signal completion of your task to native code
          	// If you fail to do this, the OS can terminate your app
          	// or assign battery-blame for consuming too much background-time
          	BackgroundFetch.finish();
          };
          
          var failureCallback = function(error) {
          	console.log('- BackgroundFetch failed', error);
          };
          
          BackgroundFetch.configure(fetchCallback, failureCallback, {
          	minimumFetchInterval: 15, // <-- default is 15
          	stopOnTerminate: false,   // <-- Android only
          	startOnBoot: true,        // <-- Android only
          	forceReload: true         // <-- Android only
          });
          I added the plugin to the config.xml file manually. I don't really trust the plugin features of the Alpha PhoneGap Build builder.

          Code:
          <plugin name="cordova-plugin-background-fetch" source="npm" version="5.3.0" />

          Comment


            #6
            Re: Background App Refresh PhoneGap

            I see you're doing a single list refresh in the code above and am curious if you have dabbled in doing background data syncs (ie running the following code on a list with a detail view in the background). At the top of this code I am just trying to figure out if a background refresh has been attempted in the last 45 minutes and if it has I don't run any of my syncing code. I am doing this because on iOS you don't have an option for how often background refreshes occur so I wanted to make sure I left the minimalFetchInterval at 15 just so I got refreshes as often as possible. I can see that my code is running because my time_sync, break_sync, etc fields are being set at the end of each if statement but it seems that this background syncing may be causing duplicate records in the database which obviously is an issue.

            Code:
                    {dialog.object}.setValue('time_sync','');
            	{dialog.object}.setValue('break_sync','');
            	{dialog.object}.setValue('insp_sync','');
            	{dialog.object}.setValue('exp_sync','');
            	{dialog.object}.setValue('pnd_sync','');
            	
            	var today = new Date();
            	var now = today.getTime();
            	var msg = "Succeed: " + today;
            	var time_msg = "";
            	var break_msg = "";
            	var insp_msg = "";
            	var exp_msg = "";
            	var pnd_msg = "";
            	var num_times = {dialog.object}.getValue('bg_refresh_tries');
            	var last_try = {dialog.object}.getValue('bg_refresh');
            	last_try = last_try.substring(last_try.indexOf(":"));
            	var last_try_dt = new Date(last_try);
            	var last_try_t = last_try_dt.getTime();
            	var time_diff = (now - last_try_t)/1000/60;
            	num_times = Number(num_times) + 1;
            	if(num_times > 20){
            	num_times = 0;
            	}
            	
                   //Everything above this is really just setting values to put in fields only I can see when logged into the app to make sure things are operating properly when testing
            
                   //If a refresh/sync hasn't been attempted in the last 45 minutes then attempt one
            	if(time_diff >= 45){
            	var timeLobj = {dialog.object}.getControl('TIME_LOG');
            	var breakLobj = {dialog.object}.getControl('BREAK_LOG');
            	var inspLobj = {dialog.object}.getControl('INSPECTION_LOG');
            	var pndLobj = {dialog.object}.getControl('PND_LOG');
            	var expLobj = {dialog.object}.getControl('EXPENSE_LOG');
            	
                    //Firgure out if a list is dirty or not. Do this to run syncs only when there is data to sync, if there isn't data to sync then just run an incremental refresh as data may have been changed by an admin on the desktop site.
            	var timeDirty = timeLobj.listIsDirty(); 
            	var breakDirty = breakLobj.listIsDirty(); 
            	var inspDirty = inspLobj.listIsDirty(); 
            	var pndDirty = pndLobj.listIsDirty(); 
            	var expDirty = expLobj.listIsDirty(); 
            	
                    //If a list is dirty then run a sync on the data and do a pull sync, if not then just do an incremental refresh
            	if(timeDirty == false){
            	time_msg = "Refreshed: " + today;
            	{dialog.object}.setValue('time_sync',time_msg);
            	{dialog.object}.refreshListData('TIME_LOG',{mode: 'incremental'});
            	}
            	else{
            	time_msg = "Synced: " + today;
            	{dialog.object}.setValue('time_sync',time_msg);
            	{dialog.object}.saveListEdits('TIME_LOG',{rows: 'allRows', pullSync: true});
            	}
            	
            	if(pndDirty == false){
            	pnd_msg = "Refreshed: " + today;
            	{dialog.object}.setValue('pnd_sync',pnd_msg);
            	{dialog.object}.refreshListData('PND_LOG',{mode: 'incremental'});
            	}
            	else{
            	pnd_msg = "Synced: " + today;
            	{dialog.object}.setValue('pnd_sync',pnd_msg);
            	{dialog.object}.saveListEdits('PND_LOG',{rows: 'allRows', pullSync: true});
            	}
            	
            	if(breakDirty == false){
            	break_msg = "Refreshed: " + today;
            	{dialog.object}.setValue('break_sync',break_msg);
            	{dialog.object}.refreshListData('BREAK_LOG',{mode: 'incremental'});
            	}
            	else{
            	break_msg = "Synced: " + today;
            	{dialog.object}.setValue('break_sync',break_msg);
            	{dialog.object}.saveListEdits('BREAK_LOG',{rows: 'allRows', pullSync: true});
            	}
            	
            	if(inspDirty == false){
            	insp_msg = "Refreshed: " + today;
            	{dialog.object}.setValue('insp_sync',insp_msg);
            	{dialog.object}.refreshListData('INSPECTION_LOG',{mode: 'incremental'});
            	}
            	else{
            	insp_msg = "Synced: " + today;
            	{dialog.object}.setValue('inp_sync',insp_msg);
            	{dialog.object}.saveListEdits('INSPECTION_LOG',{rows: 'allRows', pullSync: true});
            	}
            	
            	if(expDirty == false){
            	exp_msg = "Refreshed: " + today;
            	{dialog.object}.setValue('exp_sync',exp_msg);
            	{dialog.object}.refreshListData('EXPENSE_LOG',{mode: 'incremental'});
            	}
            	else{
            	exp_msg = "Synced: " + today;
            	{dialog.object}.setValue('exp_sync',exp_msg);
            	{dialog.object}.saveListEdits('EXPENSE_LOG',{rows: 'allRows', pullSync: true});
            	}
            	
            	
            	{dialog.object}.refreshListData('op_focus_lessons,safety_focus_lessons,safety_track_surveys,USER_DATA');
            	}
            	else{
            	var skipped_msg = "Skipped: " + today;
            	{dialog.object}.setValue('time_sync',skipped_msg);
            	{dialog.object}.setValue('break_sync',skipped_msg);
            	{dialog.object}.setValue('insp_sync',skipped_msg);
            	{dialog.object}.setValue('exp_sync',skipped_msg);
            	{dialog.object}.setValue('pnd_sync',skipped_msg);
            	}
            	
            	
            	{dialog.object}.setValue('bg_refresh_tries',num_times);
            	{dialog.object}.setValue('bg_refresh',msg);
            	//runUpdatesOnLists();
            	// Required: Signal completion of your task to native code
            	// If you fail to do this, the OS can terminate your app
            	// or assign battery-blame for consuming too much background-time
            	BackgroundFetch.finish();

            Comment


              #7
              Re: Background App Refresh PhoneGap

              They have a sync_log structure which will prevent duplicates. You should incorporate that and you shouldn't have to worry about dups regarless of whatelse you are doing. If you are already doing that, and still getting dups.....well...I'm not sure....I'd have to look at the whole app.

              Comment


                #8
                Re: Background App Refresh PhoneGap

                I've turned on the sync log and there were still cases where there were duplicates. However, more times than not a duplicate was only showing in the list on the device, it wasn't actually data that made it back to the server (ie if I cleared out the list on the device and reloaded it from the server the duplicate records would disappear). This was a ver annoying rendering error that did seem to be alleviated for the most part when I got rid of the sync log table (not sure if that was the issue but it was the only thing I changed and this issue got better).

                Now I'm actually having an issue where the duplicate records are ending up on the server, but I believe I am going to alleviate at this issue by not trying to sync the lists in the background but rather make a note that the lists have un-synced records and then popup an alert to the user that they need to try to sync the data the next time they enter the app (hoping this also makes them more cognizant of the fact they need to wait for the records to actually sync to the server and if they don't to attempt a manual sync before leaving the app).

                Comment


                  #9
                  Re: Background App Refresh PhoneGap

                  You need to keep the sync log going. Make sure to RETAIN the sync log records rather than deleting them. Then setup a process on the device where a user hits "sync" and then is frozen out from hitting it again until your process is complete or some other break happens in the process. Do not use the built in sync button. Create a multi step action where action javascript is run "synchronously". See attached images for an idea of what we do.

                  sync_log.pngsync_button.pngsync_window.png

                  Comment


                    #10
                    Re: Background App Refresh PhoneGap

                    I currently write all my own javascript code for the saving and syncing of the data for the list that way I can check different values before a sync occurs. I lock the screen with a custom wait gif that is removed only after the afterSynchronizeList function fires (I put a 2 second delay on the hide event just for a little extra wait time). This all seems to be working properly though there are definitely times the wait message disappears before my fade out message pops up (the fade out message tied to a lists detail view), which this message popping up seems to be the only thing that truly indicates the record synced properly.

                    I have also found that sometimes even when the record syncs properly (ie the fade out message pops up) the little customized message I put on the record letting the user know it hasn't synced doesn't disappear (the default indicator is the little colored triangle but I have customized it into a full colored bar that goes across the top of the record with the message "Not Synced" to help the user). It seems that when this happens it may cause an issue with the list refreshing when the app is in the background creating a rendering issue where the record will look like it is duplicated (even though the duplicate record doesn't exist on the server).

                    When everything works properly the app seems to be a delight, but it seems I am spinning my wheels when trying to troubleshoot fixes as it seems every time I have found a fix for one thing, it only causes an issue with another thing that had been working fine before (meaning backtracking doesn't really work as then the issue I just fixed becomes broken again).

                    Comment


                      #11
                      Re: Background App Refresh PhoneGap

                      Try syncing the entire record, not just the dirty fields. If you only sync dirty fields, and the sync gets messed up somewhere in the middle of the record, you can run into the issues you are having. Also, if you can limit a sync to one record at a time, then require additional user action before doing another record, you may further reduce your issues. You could also add in a check if syncing multiple records to ignore and skip a record with an issue, and require looking at that record when connection isn't an issue (such as an admin interface back at the office). Also, there is another option possible with a problem record (may not be workable in your case) and that is the removal and reapplication of the record as new.

                      Comment


                        #12
                        Re: Background App Refresh PhoneGap

                        I will try the syncing of the entire record as I have not given this a shot, however I am curious what issue you believe this may help solve (ie the issue where the new/dirty record indicator doesn't disappear or the issue of duplicate records rendering even though there aren't duplicate records on the server)? And what as far as the documentation, is there any specific reason why someone would want to always sync the entire record rather than just the dirty values?

                        My app tracks a user's work time, breaks, and other things that 99.9% of the time only involve creating a single record in a list for every day (ie there really shouldn't be more than one record syncing at a time). The only reason there would be extra records syncing is either 1) actual duplicate records were created or 2) a record from the day before never synced.

                        I wish we could use the delete and retry method as I know this would work but being the records generated are for keeping track of worker time it is preferred that these records not be deleted by the end user but rather only edited on the back end by an admin.

                        Greatly appreciate all your feedback, do you have a mobile app in use that was built using Alpha Anywhere? If so I am curious what the use case is (internal app used by just your team, app you built for a company only used by their team, or an app as part of a SAAS product, etc)?

                        Comment


                          #13
                          Re: Background App Refresh PhoneGap

                          Hi Josh,

                          We have found, in some cases, the sync fails mid stream, which will show some fields updating and others not. This ends up creating conflicts where non exist...in reality. What we have done to resolve this issue is to overwrite the whole record.

                          We have several mobile apps working in very crappy data conditions here in WV. Currently all the apps are used by industry and not for public use. We have a few public use ones being rolled out in the next few months. We do have some of our own apps coming out, but for now it's all been client based production.

                          We assume that the data connection will be as bad as it can get....and build the app for that.

                          Also, if you haven't noticed yet....turning off Wifi is NOT the same as using Airplane mode. You need to perform disconnected testing in a variety of ways. Here in WV we go from nothing, 1/2/3x up to LTE. Your device may show connection and attempt to sync, but in reality there is no way it can sync given the type of connection. This isn't such an issue in larger metropolitan areas.

                          Our company can be found at xappdesign.com. We are updating our site content, but you will get the gist of it.

                          Comment


                            #14
                            Re: Background App Refresh PhoneGap

                            I actually have write conflicts turned off which I believe alleviates that issue of a sync failing mid-way through causing write conflicts, but still going to give this a shot since I haven’t tried it yet.

                            I always test using airplane mode but even if your phone responds saying there is an LTE connection there is no guarantee how fast it is which I believe is the more crucial aspect (thought about running a pre-sync ajax callback and timing it to decide if I want to sync or not but this extra step seems like it could cause more problems than solve).

                            My hope was that I would get rid of many of the failed syncing issues by using the OS’s background refresh feature allowing me to run code when the app is in the background (specifically code to check if a list is dirty and run a sync if it is, if not then just run an incremental refresh). However, when attempting to sync a list that is dirty while the app is in the background I seem to get duplicate records created on the server, not just the improperly rendered ones on the device (not 100% sure if this was with the sync log on or off so don’t know if that will take care of my problem).

                            Looks like I have some more scenarios to test out. I feel like alpha anywhere and phonegap are so close to being the perfect development tool combination if I could just get these final issues fleshed out.

                            Comment


                              #15
                              Re: Background App Refresh PhoneGap

                              In our experience turning off write conflicts helped, but didn't get rid of the issue entirely. Using the sync log, without deleting it initially, and overwriting the whole record solved most of the issues. Then, we modified the interface to allow sync of one record at a time and made sure they can't rehit the sync button until the process stopped. If you aren't doing things with images, and it's just regular text data, then this should solve most of your issues.

                              Comment

                              Working...
                              X