I do a service on Android , which every N seconds accesses the web service. I need to compare the responses from the web service to each other, such as "previous / current". But how to store data between them, because every N seconds a new instance of the class is created that is responsible for accessing the web service? If not in it, then where?

    2 answers 2

    Get yourself an Application object - you need to declare it in the manifest and put your Hashtable there, overlay it with getters / setters and that's it.

    • And if the system restarts the application, then what? - KoVadim
    • Well, if you need something you can organize serialization - what's the problem then? It only seems to me that in the production of a topstarter such a need is unlikely to arise. - Barmaley
    • But about serialization not a word. Therefore, I think your answer is a bit harmful. I myself saw the program, which adopted the same technique. Developed scold the android, but they do not want to do it right. - KoVadim
    • And for me, your statement of the question is that it is slightly more harmful to serialize ... - Barmaley
    • This option would fit more, but I decided not to bother my Hashtable.toString () and put the application in the SharedPreferences. I do not need to keep it between application launches. Thanks for answers! - fundottz

    And anywhere. For example, in the database. Or in a separate file (it all depends on the size and type of the result).

    For example, I would have stored in the database, making a breakdown into fields. It will be rather convenient to compare if each time is attached to the record (preferably in utc). It is possible and the auto-increment field, in most cases, you are unlikely to let him in the second round (but I had it :)).

    • I need to keep one Hashtable (previous answer) and keep it updated. The size of the data is small - up to a dozen lines only. The response history is not required. I think it would be cumbersome to use it for this purpose) can it be easier to eat options? - fundottz
    • as for me - so is the base itself. Or, less like - file. - KoVadim