How to restore last values of listview and other views after coming app from foreground?
-
30-09-2019 - |
Question
When i click home button and then come back to to my application it doesn't show the last values on the listview or any other view it just look same with when i started the application.I believe it is can be done with onResume and onPause but i couldn't find how .
Solution
Multiple ways to do this:
- An SQLite database
- Store the data as a file on the SD card.
- SharedPreferences for the activity.
- As a static variable in the Application class.
Switching between Android activities
Had asked the same question some time back.
OTHER TIPS
You can store all values in SharedPreferences
in onPause
, and then load them again in onResume
and populate your views using that data.
To get a full understanding, read about activity lifecycles and saving activity state here.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow