Search code examples
androidsaveresume

Data seems to stay saved even after closing and re-opening Android app. I don't want it to


I keep adding data to a List as my app runs. When I close it and run the app again, the old list is somehow still there and the new data is added to the end of it. I don't want this to happen and I don't know why it's happening... I think I'm initializing it properly and closing things with onPause() and onDestroy().

I'm not quite sure what's going on or where, and maybe the problem is from elsewhere in the code... All I know is that the app is not working right (on the first run it doesn't work like its supposed to, but when I close it and run it again it works just fine). And this was the only fishy, seemingly related problem (?) I could find in several hours. I don't even know what part of my code to post so I'm not looking for any specific answers, but any insights, ideas, or tips would be greatly appreciated.

EDIT: Okay, I fixed the specific issue with the List, by initializing it in OnResume(), as suggested. However, the problem remains that on the first run, things are derpy, but closing and reopening it fixes everything. It seems like there's still something going on that transfers over...


Solution

  • Read these...

    Application Fundamentals

    Activity

    In particular learn that the concept of an app is not the same as any individual application component such as an Activity. Also understanding the Activity life-cycle (creation, starting, resuming, pausing, stopping, destruction) is paramount to understanding where and when to perform various actions.

    Sorry - a bit of a generic answer but as you haven't provided any code it's not possible to give anything definitive.

    One thing I will say though is both of those links above when combined would probably solve 50% of all the common Android questions I see here on SO.