I am using Android Annotations in my project.
I am performing a set of tasks in background threads. Each background thread contains a call to a REST endpoint(using Retrofit). All calls are synchronous at this point. I am trying to cancel all threads if I leave the app(in onDestroy of the fragment).
My code is structured something like this
@Background
void bgMethod1(){
//call rest endpoint get response
uiThread1(response)
}
@UiThread
void uiThread1(){
some UI related changes = show toasts etc
bgMethod2();
}
@Background
void bgMethod2()
//call next rest endpoint get response
uiThread2(response)
}
@UiThread
void uiThread2(){
some UI related changes = show toasts etc
bgMethod3();
}
And so on and so forth... At any point while these threads are running, if I quit the app(press the back button), I want to stop all these threads from running(stop the current REST call as well as all future calls which )
I am currently referring to this github page for Android annotations
https://github.com/excilys/androidannotations/wiki/WorkingWithThreads
I have tried to use BackgroundExecutor.cancelAll inonDestroy of the fragment to no avail. All the methods execute(all REST calls are made sequentially).
How do I stop all the threads from executing/cancel as well as stop the requests, both ongoing and future, made by Retrofit in these threads.
All the methods in my Retrofit REST interface are synchronous and have a return type.