Currently I've got a TouchDB instance embedded in my main activity and have now hit a point where a separate fragment needs access to it and mearly passing data from the main activity to other activities isn't enough. Is there an recommended way of sharing the same db instance between activities/fragments? For instance in the image below which is similar to my app, fragment b requires access to the db, but on mobiles it'll be attached to Activity B and tablets Activity A (the main activity in my case).
Would extracting the db implementation out of my main activity and putting it in a singleton class be the recommended way? Or instantiate and destroy the db in each activity/fragment? If the later is the prefered approach is my understanding right in that, apart from the main activity it would be best to have the db implementation in the fragments rather than their related activity?