function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PanchoPancho 

Android activity refresh problem with multiple salesforce queries

I have an Andoid app that performs multiple salesforce queries to update one screen in an activity.  I am running into a refresh problem with the screen because all of these Salesforce queries are each an asynctask.  I tried putting all of the salesforce calls into a master asynch task so I could use post execute, but that didnt work.  I read about Android loaders here, http://developer.android.com/guide/components/loaders.html   Has anyone used loaders to fix this issue, or is there a different way I can address the issue?  I need to know when all of the salesforce queries are complete so I can refresh the screen.

 

Thanks for your help. =o)

 

Gaurav KheterpalGaurav Kheterpal

One option you can consider from a usability perspective is - Instead of firing multiple Saelsforce queries directly from your app code, create a RESTful API which does all the SOQL stuff (one ore more queries) and call that from your app. That would significantly reduce the complexity of your Android app code as well as the amount of requests being fired. You can keep the API signature customisable to fire whatever queries you want and process response accordingly.

 

Or is there a specific reason you don't want to handle this on the Salesforce side and instead do it on the app side?

PanchoPancho

It might be helpful if I explain the scenario a little more.

In our business we have a team of people who go out and visit retail stores to train retail employees on our products.  We have a number of custom salesforce objects that support the business:

  •                 Retail Store – with address, name, ranking, etc.
  •                 Retail Employee- people in the stores.  We track their training and sales.
  •                 Store Visit – tracks what took place during a particular store visit.
  •                 Check-in – GPS/time allows our team to check-in at locations.

In my Android application, I have a Store Detail page which shows:

  •                 A particular store’s fields-name, address, phone, etc…
  •                 Employees at that store, and their performance
  •                 Previous visit information
  •                 A check-in and check-out function
  •                 A picture of the store, which is an attachment to the store record

This represents 5 different queries.  It is so easy to do on a Visualforce page, but difficult to pull all of this together on one Activity(page) in Android because the multiple queries are all async processes and I cant control when the page is completely updated from all the queries and able to be displayed.  It would be great if we had an “onPostExecute” with the Salesforce API similar to what you can do with Asynctasks in Android.

Any ideas on a solution?

Gaurav KheterpalGaurav Kheterpal

Interesting. Have you looked at the RestClient class and the sendAsync() method? You might want to use a sleep/ timer to ensure you get the order right. It may not be the cleanest approach but I think that might work. Thoughts?

PanchoPancho

I'd rather not use a sleep timer becuase responses are going to be drastically different.  I will have employees using this on wifi, 4G, 3G, and 2G out in the field.

 

I really need something like “onPostExecute”, or a different way to handle “onPostExecute” after the async calls.  

 

Any ideas anyone?

Julian.SuarezJulian.Suarez

What I would do is instead of using async task or calling the APIs ..Async methods, I would use a Service create a new worker thread and then execute everything Synchronally from that service. There is a nice subclass of Service called IntentService which implements the worker thread pattern I mention.

 

Although is perfectly fine to use AsyncTasks to call a WS, there are complex issues like handling configuration changes (rotating the screen) so the best way is to use one of the patterns described here http://www.google.com/events/io/2010/sessions/developing-RESTful-android-apps.html.

 

It is no easy task but the result is much better. I recommend you to checkout this library https://github.com/foxykeep/datadroid