Reputation: 14638
I have an activity which is basically a tabbed activity for keeping a score a of cards game.
The problem is that, when I get phone call and I come back to my app, then the score is cleared!
It seems like activity is restarted a phone called is received. Why is this happening and how can I fix that?
Thank you
Upvotes: 1
Views: 411
Reputation: 82533
Android devices had limited memory, and can only run so many apps at once. Phone calls are one of the most taxing tasks on a mobile's hardware, as audio streams aren't exactly small on memory usage.
Due to this, I think your app's current instance is killed to free up RAM, and this results in a loss of scores for you.
To fix this, you could write the value of the scores to SharedPreferences in your Activity's onPause()
and then retrieve them in onResume()
.
Upvotes: 3