-1

I've got an activity and I want to keep everything inside it (Bitmaps, texts, buttons..) so when the user restarts the phone and clicks on my app, everything is like the last time he used it.

Any idea?

I've been reading about the lifecycle of an application in Android, and i know the basics theoretically but I don't know how to implement it.

Thank you.

Swayam
  • 16,294
  • 14
  • 64
  • 102
Aldridge1991
  • 1,326
  • 6
  • 24
  • 51

2 Answers2

1

Actually, you don't need to do anything on objects such as Buttons and TextViews, since they do not change during your Activity's lifetime. When your application restarts, they just get recreated and they look the same anytime. Things that you want to save are possibly user inputs or downloaded files. If you have any of these, then I'd recommend learning this post, it describes different data storage mechanisms in Android. For different kinds of data you'll need different solutions, for example text inputs can be saved in SharedPreferences, but bitmaps should probably be saved in the file system. Hope this helps.

Egor
  • 39,695
  • 10
  • 113
  • 130
0

Maybe it is not the best solution, but you can try SharedPreferences and save different user data into different variables upon exiting.

When the app is restarted, read the values stored in the SharedPreferences and display these values in your respective views.

Other than SharedPreferences, you can also try out these various options according to the type of data you would want to persist!

Swayam
  • 16,294
  • 14
  • 64
  • 102