Frage

There are a few Fragments in my main activity. Different adapters are used in different fragments. Those adapters are used to make http requests to my web services.The requests work well except that it requests too frequently sometimes, for example when the device rotates. Actually I don't want to request if the last request is not long enough, for example, no more than 30s. But the problem is the Fragments will be recreated when the device rotates. So that the adapter will also be recreated and then the http request will be made.

Of course I can create a global queue for the request so that I can ignore the request when last the request is no more than 30s. But the fragment will be empty if I don't request because it's a brand new fragment.

Can anybody advise what the best practice for a proper http request in Android? Thanks

War es hilfreich?

Lösung

How about using an IntentService or ContentProvider to manage the requests i.e maintain a timestamp of the last request and only process the web service request if the last request was made X seconds ago.

While the fragment is waiting for content, show a ProgressBar (indeterminate = true)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top