1

I am creating dynamic views, Adding them to the layout those views are adding fine.But once i close the app and open it Dynamic views are not visible,I want to display those views after opening the app second time. Will you give me any idea, Thanks in advance.

1 Answers1

1

You'll have to manually add the view's state to the saved instance state bundle, and recreate it from there.

This is accomplished by overriding onSaveInstanceState() on your Activity and/or View. The state will be later available in the creation Bundle (onCreate(bundle)). You can use that data to re-instantiate your views.

The correct OOP way of things would be to create a class for your dynamically created view that implements a custom onSaveInstanceState() method, and then packing it and unpacking it into the Activity's bundle.

This blog post contains details and examples on how to tackle the issue. Some more related info in this other SO question

Community
  • 1
  • 1
salezica
  • 74,081
  • 25
  • 105
  • 166