In our Android app, we're using 3rd party vendor for Chat service. We need to create session for the user, then login to use the service and then have to fetch messages. All are separate HTTP requests which needs to be called inside one's success callback. So how can I make it, like below.
ExternalService.createSession(param1, param2, new Callback<Session>() {
void onSuccess(Session session) {
session.login(new Callback<User> {
void onSuccess(User user) {
user.getMessages(new Callback<List<Messages>> {
void onSuccess(List<Messages> messages) {
// This is original place where everything is success
}
void onError(Error error) {
}
}
}
void onError(Error error) {
}
}
void onError(Error error) {
}
});
If I run in the Activity
, it is working fine no issues. How to do it in a Service
? Because in Service
also I have problem running AsyncTask
, throwing error "Can't create handler inside thread that has not called Looper.prepare()"
. Service
exits after calling the AsyncTask
and reaching end of handleAction
block.(I understand, that is the behaviour Service
). But how can I achieve without using Looper
? Or if there is no other way to do without using Looper
, how can I stop it after accomplishing what I need ? What is the best approach to do this ?