0

The app is to communicate with a bluetooth device with assorted data (config, measurements, service logs, status telemetry) - and it should cache obtained data so the user flipping between activities doesn't need to re-download everything when coming back to a prior activity, or the data was obtained in a prior activity (e.g. the "Summary" activity gets chunks of data from others).

That means a cache object which should hold this data - and be a single-instance class.

It's been hammered into my head that Singletons Are Bad. But with Android apps having multiple entry points, I can't guarantee a single initialization path for the app or the lifespan of the object, so I'm not sure if the singleton is still wrong here - or if so, how to approach getting the single-instance class right in this scenario. What form of single-instance object should I use, to initialize it on creation and access everywhere?


Xamarin, C#, if that's of importance.

asked Jul 16, 2019 at 8:08

1 Answer 1

1

In this case I would utilize a Singleton, created when the user first needs to read or write data, backed by a database. This Singleton could be provided through a dependency injection framework (and thus not be a real Singleton) but it depends on what xamarin can offer you.

Singletons are generally bad, but only because they tend to be overused and there is often a better solution to a given problem.

I am not sure what tools xamarin give you to work with a database.

answered Jul 16, 2019 at 10:55

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.