0

Is there any way within Android to schedule sequential services, similar to sending ordered broadcasts for BroadcastReceivers? What I mean is that I'm looking for something where I can start service A. Once service A completes, start service B. However, this gets a little more complicated because service A won't always need to be started, only sometimes.

More specifically, I have an activity that allows users to search for content. In order for me to make an HTML request (using Retrofit) once the user enters a query, I need to supply an access token. The access token is only valid for an hour. However, if a user makes another search request within that hour, there's no need for a new access token. Here's a quick logic diagram:

enter image description here

I've looked at JobScheduler and JobDispatcher, as well as Android-Job from Evernote. However, they all appear to do the same great things: start services when certain constraints are met. However, I couldn't find anything about handling multiple requests, specifically where one request is dependent on another.

Would anyone be able to provide some insight into this? I've thought about doing this with BroadcastReceivers as well, but couldn't think of anything that'd be a robust solution. Any help on this would be greatly appreciated! :)

coolDude
  • 647
  • 2
  • 11
  • 27
  • Did you checked WorkManager API(part of JetPack), using that you can create chain of jobs - https://developer.android.com/topic/libraries/architecture/workmanager/advanced – Vamsi Nov 07 '18 at 06:36

1 Answers1

0

I don't understand why you wouldn't just have service A conditionally schedule (or just start) service B according to whatever logic it wants.

Or, factor the work the services perform into some other abstraction, and conditionally link them all within the context of a single service.

Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134
  • I could do what you're recommending. However, I was wondering if there's already something out there that handles my issue. I was hoping to make use of one of the scheduling frameworks offered within Android to play around with them (`JobScheduler` etc.). I understand if it's not practical to use them for my case though. – coolDude Oct 30 '18 at 19:38
  • It's not clear to me what that other something would do, if it existed. You still need to write the logic for "goto next" somewhere. I guess you are looking for some declarative non-code way to chain together work elements? It'd need to be extremely general to allow for arbitrary "goto next, or not" logic in that framework. – Jeffrey Blattman Nov 06 '18 at 18:05