I need to write a common class for handling http request in the background thread ..i have 4 diffrent ui activities which all wants use the same class to fetch web data and update in their activity… My ui activity wants to just call background class and it should not wait for data..background class only need to post the datato ui thread then ui thread will handle that data… I tried using Asynch task…but it works when i implemented in the same ui class… Can some one give better approach to implement in common class ..and also I have confused between which one to go with asynch task or handler with runnable thread…
Share
Write a service that runs in the background and polls the server for data (use an
AsyncTaskor some sort of thread to perform the query asynchronously). When data is received from the server, insert it into a local database (aContentProviderbacked by anSQLiteDatabase, for example). Then have theActivityquery the local database whenever it needs new data. The advantage here is that you will still be able to display data even when your device is offline… the local database acts as a cache that holds previously-queried data.