In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of android's method of dealing with configuration changes, the content is detailed and easy to understand, the operation is simple and fast, and it has certain reference value. I believe everyone will gain something after reading this android method of dealing with configuration changes. Let's take a look.
1. Configuration change
Some device configurations may change at run time (such as screen orientation, keyboard availability, and when the user enables multi-window mode). When this change occurs, Android restarts the running Activity (calling onDestroy () and then onCreate ())
If this problem is not addressed, it will result in the loss of data that is already bundled to the control. Here are two solutions to this problem (the first is to save the data, and the second is to configure the data not to be lost).
two。 Handle configuration changes: retain objects during configuration changes
Can be implemented using viewmodel
3. Handle configuration changes: handle configuration changes on your own
3.1 prevent activity restart through configuration
You can declare that Activity handles configuration changes on its own by configuring the configChanges property in the activity standard, thus preventing the system from restarting Activity, whose value represents the configuration to be processed
To prevent the screen from turning, you need to configure "orientation" and "screenSize"
The "keyboardHidden" value prevents rebooting when keyboard availability changes
3.2 configuration change snooping
If you need to do something after the configuration change, you can change it from writing onConfigurationChanged to listening as follows: listen to the screen direction code.
@ Override public void onConfigurationChanged (Configuration newConfig) {super.onConfigurationChanged (newConfig); if (newConfig.orientation = = Configuration.ORIENTATION_LANDSCAPE) {Toast.makeText (this, "landscape", Toast.LENGTH_SHORT). Show ();} else if (newConfig.orientation = = Configuration.ORIENTATION_PORTRAIT) {Toast.makeText (this, "portrait", Toast.LENGTH_SHORT). Show () }} this is the end of the article on "how android handles configuration changes". Thank you for reading! I believe you all have a certain understanding of the knowledge of "android's method of handling configuration changes". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.