I load a layout in the main Activity’s onCreate() method via a layout inflater. I would like to offer alternative layouts a user can set in my app’s Settings.
Is it simply a matter of invalidating the current view and inflating the new layout in the settings code when the user makes the setting change prior to returning to the main activity? Or do I need to add if statements to the Activity’s onCreate to inflate the set layout and therefore require the user to restart the app after changing the setting?
Thanks
When the user navigates from your main activity to the preferences activity, your main activity enters
onPause()lifecycle method and your activity goes to background. you lose reference to the main activity. After the changes are made to the shared preferences and and the user presses back button your main activity is brought to fore ground. You could add a conditional statement inonResume()to check Whether the user has chosen new layout.I presume that you are invalidating a view in your activity rather than trying to refresh the entire layout of your activity (which you can do by passing a new layout to
setContentView()inonResume()albeit with conditional statement to match your requirement).