mercredi 6 décembre 2017

Singleton class that show a toast in different activities using resources efficiently

I have a singleton class (let's call it: SingleWorker) that it's used in multiple activities. Depending on the case it shows a toast or a progress dialog if a task is being done. I have 2 ways in my mind on how to do this:

1) creating a separate method in the singleton - SingleWorker, that will get the context of the activity before the toast/progress is shown

2) in the extended Application singleton, I will store, every time I enter a new activity (and on its onResume) its instance, that i will then use that in the SingleWorker singleton.

Which one is the better choice (I guess the first one), can I do it better? I tried to find an efficient answer by myself, but I need a direction or a tip. Any idea, suggestion, advice or link is gratefully received. Thanks for reading !

Aucun commentaire:

Enregistrer un commentaire