Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid recreating activity when Dark theme was changed outside of app

When the user changes the system theme from the notification menu, my activity getting recreated and data is loaded again, which is not my app's requirement.

Is it possible to prevent a system theme change from affecting my application in this way?

like image 424
maqsats Avatar asked Nov 01 '25 06:11

maqsats


1 Answers

Don't stop the theme change instead store your data in viewModels.

The ViewModel class is designed to store and manage UI-related data in a lifecycle conscious way. The ViewModel class allows data to survive configuration changes such as screen rotations or theme change.

Have a look : viewModel

like image 58
DrHowdyDoo Avatar answered Nov 03 '25 20:11

DrHowdyDoo