Minimizing app deletes views and reinserts programmatically inserted views


As soon as I suspend my app and resume, some of the views my app has disappear. One of the text fields get focus as soon as application resumes and the Android keyboard appears, pushing some of my views upwards and one of the buttons disappear. Also, some of the programmatically inserted elements get inserted again.

The programmatically inserted elements get inserted through a function called by the onLoaded event of the main page element. Looks like onLoaded event gets called again as soon as the app resumes, effectively reinserting previously added elements.

How can I solve these problems? Prevent duplicate execution of functions, and prevent my buttons from disappearing once the application resumes from suspension.