You need to sign in to do that
Don't have an account?
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)
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?
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:
In my Android application, I have a Store Detail page which shows:
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?
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?
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?
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