Given:

  • several activations
  • several fragments
  • coordinate receiving service

When the coordinates are received - they need to be saved somewhere, so that they are then available for service and if the user opens the application - for activation too. And when getting new coordinates - update them in these variables.

What is the best way to do this?

I look in the direction of SharedPreference

    1 answer 1

    SharedPreference will be best because:

    1. No matter where you get / write data (service / activation / fragment)
    2. They are recorded synchronously and it does not happen that old data is in one place and new data in another.
    3. Unlike static variables of class class there is no probability of class unloading from JVM
    • Thank you, Yuri) Regarding the SharedPreference, I am interested in another question: how quickly does a variable write there? Those. If I wrote it down and literally right away I need to use it. - researcher
    • @researcher, it seems, if I correctly understood what I read about it, access to this data goes in turn, and writing / receiving data goes in the order of calling these operations. Those. if you start writing something there, you will not be able to read something until the recording is completed. - Yuriy SPb
    • one
      Thank. I read about this. - researcher