Will android kill my singleton?

Question

I know, that probably this question (in different interpretations) was asked many times, but I wasn't able to find the exact answer to my question.

I'm trying to understand concept of Android, but there's one thing that is unclear for me. I know that Android can kill my Activity instance and I should store the internal state of that instance via OnSaveInstanceState. Android will later recreate activity and pass me an object Bundle so I can restore my internal state.

But I don't know what will happen with plain Java classes, which don't not inherit any of Android stuff like Fragmentactivity and so on. I'm basically talking about one class which implements singleton pattern and is used to store data shared by many activities/fragments.

Will my singleton be killed? I expect it to be killed only when application is stopped via settings or device rebooted. Data which is long term is already stored via sqlite.


Show source
| java   | android   2017-11-29 18:11 1 Answers

Answers to Will android kill my singleton? ( 1 )

  1. 2017-11-29 18:11

    Will my singleton be killed?

    It will go away when your process does.

    I expect it to be killed only when application is stopped via settings or device rebooted.

    Your process may be terminated at any point when your app is not in the foreground. Only use a singleton for a cache or other information that is not needed once your process is terminated.

Leave a reply to - Will android kill my singleton?

◀ Go back