If you want to try to save data through instances, you can put them in a static variable. A typical example: you have a specific disk loading state, so you create a global singleton that loads data on the first instance, and then additional queries for it use the same instance (without reloading the data). When a new instance of your service retrieves a singleton in its onCreate (), it does not need to be reloaded if the previous instance of the service has already requested it.
When performing such a design, it is very important to understand the life cycle of your process and when it can be killed. Otherwise, you may lose data at rather random points when your process is killed during normal operation.
source share