I am building an Android library for our platform and I'm struggling with how to allow my users to pass a function that gets called at certain times in the library.
The library starts an Activity, that activity has some service classes that point to my https API. (oversimplification but hopefully thats enough detail)
What I want to provide is a way for my users to pass a callback that generates the auth token for the API, allowing them to generate it themselves. Maybe the interface might look like String getAuthToken()
.
But how can I do this without losing state at some point? I started with a Singleton when the library starts up (it starts an Intent for the main activity of the library), but when the process gets killed and you try come back to it then of course the app crashes, the singleton was set up before the activity started.
Am I missing some obvious pattern in Java or Android that solves this?