Home > database >  How can i update an activity in android studio
How can i update an activity in android studio

Time:02-06

I've created an app with two activities. On the second activity i can create new buttons by pressing a floating action bar button inside the activity; but the problems is when i return to the main activity and come back all the added buttons are gone.

I was wondering how can i save these added views so whenever i exit that particular activity or the app entirely, views won't perish.

I know i can save the views' values by "Preferences" commands but that only can save the views' parameters not themselves and if i go that way i have to recreate each view again each time i enter the activity.

if i could update the activity whenever views are added to it that would be excellent.

I would appreciate any help.

CodePudding user response:

You can save information about views in preference like number of buttons created. for example you clicked button 4 times then save numOfButtons value as 4. In onCreate method you can check values of numOfButtons and execute that block of code 4 times to generate buttons.

CodePudding user response:

The activity view itself cannot be preserved as it gets destroyed after it is removed from the stack. However, you can use custom XML layouts and then use them wherever you want.

  •  Tags:  
  • Related