Question

I'm interested in using Ion/AndroidAsync for the "backend" of an Android app. I don't want to make long running calls tied to an Android component, so I have a background layer that stays alive as long as the Application is alive. This background layer has an API that allows the UI to make async calls to perform different tasks, and returns a Future to the UI (also allows for a callback that gets executed on the main thread) so that it can be passed between components if need be.

I like Ion's API, but don't want to call it from an Activity; rather, I'd like to use it in my background layer, since a "task" may also need to do other long running operations in conjunction with a network call. That being said, will I run into any issues if I pass an application Context to Ion.with()?

Était-ce utile?

La solution

It will work fine with an Application Context. It will never cancel any requests, as the Application context never dies. But that is what you want.

Autres conseils

  1. My project is using Ion default instance with Application context request for all images.
  2. http://www.programcreek.com/java-api-examples/index.php?api=com.koushikdutta.ion.loader.HttpLoader
    this open source example use a context to get the application context. so , you can use applciation as well.
  3. But Ion instance has the Application reference,I think the long task may cause the application instance leaks .
  4. Ion.getDefault(Context context).cancelAll(Object o); It's mananger your request task better for you application.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top