Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
139 views
in Technique[技术] by (71.8m points)

java - Attribute android:configChanges and it's accepted values

Okay, so I know literally know nothing of Java and minimal of Android. With that said, I have run across a certain attribute or variable in almost all of my manifests.

< android:configChanges="1204" >

Now, I know what and why the code line exists and what it is mainly used for (screen orientation, keyboard or screen size) but I am wondering what the numeric value is referring to. Would it be set somewhere or is 1204 a known value associated with the attribute android:configChanges? And if the value is referring to the configuration state change ie. orientation of the screen, that would imply that it is defined somewhere. How would that be written in Java? Going further, if it is defined somewhere wouldn't that mean it is able to be used for other means and not just android:configChanges? I am searching for some answers as to what is going on with my phone.

Android 10 on LG Aristo 5 for Metro. Any help will do thanks!

question from:https://stackoverflow.com/questions/65660473/attribute-androidconfigchanges-and-its-accepted-values

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The hardcoded number

I assume you're viewing a compiled app's AndroidManifest.xml. Typically in production code the XML flag attribute would look like this:

android:configChanges="locale|orientation|screenSize"

1204 is a decimal value. Interestingly I just opened the same file in my app's APK and configChanges was a hexadecimal value. It's indicated by 0x prefix, e.g. 1204 dec would be 0x4b4 hex. I'll also mention binary numbers for completeness' sake - they'll be used in an example below.

Now this is beyond my knowledge, but I guess the difference may be somewhere between AAPT2 versions or it may be applied by an additional code optimizer like R8 or ProGuard.

configChanges and bit masking

is 1204 a known value associated with the attribute.

Kind of. It's one of possible combinations of configChanges flags. They are known, there are just a lot of them.

For example, take a look at this pair of constants (or any other pair, which you'll find nearby in these files):

  1. locale flag in configChanges attribute in attrs_manifest.xml.
  2. android.content.pm.ActivityInfo.CONFIG_LOCALE

The value of these represents a bit in configChanges, which itself is a bit mask. This means that having just the value of configChanges you can check which of all these flags are enabled and which are disabled.

Checking enabled flags

We can use an online tool such as BitwiseCmd to perform bitwise operations on those values.

For example, we can perform an AND operation on 1204 and the locale flag:

1204 & 0x0004

    0000010010110100 // 1204 (configChanges bit mask)
&   0000000000000100 // 0x0004 (locale bit)
=   0000000000000100 // 4

This means that in 1204 the locale flag is enabled and the Activity will not be recreated when system locale (language) changes. In simple terms an Activity represents a window on your screen.

Let's check the uiMode flag for contrast:

1204 & 0x0200

    0000010010110100 // 1204 (configChanges bit mask)
&   0000001000000000 // 0x0200 (uiMode bit)
=   0000000000000000 // 0

This means that in 1204 the uiMode flag is disabled and the Activity will be recreated whenever UI mode (day/night) changes.

Here's an example on how how to check those flags in Java.


I am searching for some answers as to what is going on with my phone.

Are there any issues you're encountering or is this just pure curiosity?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...