Sorry if this is a dumb question. I'm very new to Android.
I have written a library that uses a library that uses a binder service. That is, my library has a class that derives from a library class which uses binder.
My library is intended to provide that data via an API in a platform-independent way (it can't expose a binder dependency). For this discussion, let's say it has a "Start" and "Stop" function. Start spins up the service if the ref-count is zero, and increments the ref count. Stop decrements the ref count, and when the ref count goes to zero I want to shut everything down, run clean-up code, etc.
All the documentation I can find says I have to call startThreadPool and joinThreadPool to receive binder events. But joinThreadPool blocks, so the Start function never returns.
This means binder subscription needs to happen in a thread. But even if I put the call to joinThreadPool in its own thread I don't know how to make joinThreadPool cleanly exit so I can clean up.
So I tried creating a thread that just calls startThreadPool and spins in a sleep loop while an atomic is set; Stop clears the atomic. This works in theory, but my debugging seems to show that if I try to end the process that is using my API I get a "binder exited" event before my cleanup code can execute.
The basic question is: how do I use binder in a non-blocking way, and then leave binder and clean up?