I have a simple chat app where a RelativeLayout with multiple views is created for each message. After the activity is stopped or destroyed all of my added layouts disappear from the parent so all messages are gone.
Sure I could put the ID (along with other values) of each single view into a SharedPreferences object or a database to restore all messages after the activity is re-created.. but is there a simpler way to save the dynamically created layouts..? The parent is defined by XML.
When an
Activity(or aFragment) becomes invisible – itsViewhierarchy gets destroyed, and you can’t overcome that. In fact, you don’t need too. The solution is to store the messages inside a database and recreate theViewhierarchy onActivitystartup based on the database contents. No need to reinvent the wheel here. Hope this helps.