-
Notifications
You must be signed in to change notification settings - Fork 545
Advanced RoboSpice Usages and FAQ
This page is dedicated to explain advanced RoboSpice usages and answer frequently asked questions
You can cancel a pending request by either
- using the request object itself and cancelling it
- cancelling a request using its cache key and result type via the spice manager. This is preferred as the cache key can be saved in the onSaveInstanceState bundle.
The first mechanism is hard to put it place on Android as you can loose a request object very easily (during a rotation for instance) but can still be considered in some simple cases (where rotation is blocked for instance).
The SpiceManager will let you add a listener to a request if such a request exists by using :
- spiceManager.addListenerToPendingRequest
This will not execute any request, just add a listener. If no such request exists, it won't do anything.
Use spiceManager.getDataFromCache() using the result type and the cache key as a compound key to identify request's result in the cache.
The core of RoboSpice is dedicated to networking but no to HTTP. It is protocole-agnostic and that provides the ability to use RoboSpice for HTTP/SPDY/FTP/etc. networking.
If you decide to use a more specific technology in conjunction with RoboSpice for handling an HTTP scenario, such as Spring Android, Google Http Java Client, etc. they will provide you, or not, with the headers of the response.
For instance [http://static.springsource.org/spring-android/docs/1.0.x/reference/html/rest-template.html](Spring Android RESTTemplate) does have "entity*" versions of its methods that can give you back the headers. But again, this is not the responsibility of RoboSpice.
When you execute a request using the SpiceManager, you can provide a duration of expiry. This duration indicates whether or not to use any data in the cache, if there are some. It doesn't indicate any expiry duration of the data that the current request will fetch from the network.
Report to question above to get the HTTP headers and use the returned value for data expiration to give an expiry duration to your next request.
Yes, you can, and that should be the best option around. RoboSpice has been designed for networking requests but we acknowledge that it addresses a more general problem : syncing long running background tasks and activities.
To perform such a task using RoboSpice there are 2 steps to follow :
- build you request as usual but don't use any networking in the method "loadDataFromNetwork"
- provide your Spice Service with a custom NetworkStateChecker that will always declare the network to be available. This way, RoboSpice will always execute your requests (usually, requests are simply discarded if network is not on).
RoboSpice ships with debug logging enabled to help you during development phase. If you want to turn it off just put this line of code in your SpiceManager subclass's constructor:
Ln.getConfig().setLoggingLevel(Log.ERROR);