Issue
I programmatically create a RelativeLayout with some other views inside it and add it to the parent which is defined in XML. But all the views (incl. the layout) that were created programmatically disappear after the activity is re-created. Do I need a SharedPreferences object to save the values and then re-create the layout or is there an easier way to save it?
P.S. all new created views get an id assigned
Solution
Do I need a SharedPreferences object to save the values and then re-create the layout
You say that you are creating these widgets in onResume()
. Your code in onResume()
needs to know what widgets need to be created. If this is purely transient information, and you are worried about things like the activity being destroyed and re-created due to a screen rotation or other configuration change, use onSaveInstanceState()
on the activity or fragment to pass data about these widgets from the old to the new instance of the activity. If, on the other hand, you are worried about being able to re-create these views several months later, you need to store this information persistently: SharedPreferences
, database, some other file structure, "the cloud", etc.
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.