views:

39

answers:

2

In my android application, I am using the tab view and so I have two tabs: parameters and results.

the user enters the various parameters on the first tab and then switches to the second tab to view the results.

i have a service that performs some long-running calculations. the user enters parameters on the first tab and hits 'calculate'. They can make adjustments and hit 'recalculate' and the service is updated with the new parameters.

As these calculations progress, I want the user to be able to switch to the results tab to view the results of the latest calculation. They would then view the results and be able to switch back to the parameters tab to make adjustments.

I can think of two approaches:

-register the 'results tab' with the service and when the service reaches a milestone, it calls directly to the 'results tab'.

-have a timer running in the 'results tab' and have it query against the bound service on a regular interval and update accordingly.

Do people have comments or recommendations for these two approaches?

+2  A: 

AsyncTask has a publishProgress method that should make it really painless to push updates from your background task to the UI thread.

Mayra
i've updated the original question with more details on the UI. It looks like this Task is not going to work as I need to periodically push out changes to the long-running task and have it continue.
isolatedIterator
A: 

Don't use polling (your second bullet).

CommonsWare