Why android.os. Creating the last class?

I recently ran into some problems with android.os.Bundlewhich I was hoping to fix by simply extending the class and making it more weakly printed. The specific problem I encountered was errors such as:

W/Bundle  ( 6782): Key access_token expected byte[] but value was a java.lang.String.  The default value <null> was returned.
W/Bundle  ( 6782): Attempt to cast generated internal exception:
W/Bundle  ( 6782): java.lang.ClassCastException: java.lang.String
W/Bundle  ( 6782):  at android.os.Bundle.getByteArray(Bundle.java:1305)

Of course, converting from Stringto is byte[]trivial, so I thought it’s easy Bundleto do this conversion automatically if it searches byte[], but finds instead String. It is foolish that this is no longer the case (and also that it has certain getters and setters for almost all primitive types and several different types Objectinstead of general ones that work only with Object, or for the worst Number, Stringand Parcelable), in my opinion.

But in any case, I quickly discovered that I could not fix the problem by expanding Bundlebecause it was declared final. Is there any known / specific reason for this? There are other classes in android.osthat are not final, and what makes Bundlethis binding worthy of?

Also, any ideas on how to get around this? The wrapper class is missing because there is no ordinary wrapper class interface(the code that actually causes the problem is part of a third-party library, so I can’t just update it to refer directly to the wrapper class),

I assume that this excludes the only way to find all the places in the code that, as it turns out, set values Stringfor things that third-party code expects to transmit as arrays of bytes.

+5
3

"" . . , , . , Bundle . , , , . , , , , , , .

+1

String, , Bundle, ?

Bundle.putByteArray(String string) <<== ??

putByteArray(), ByteArray putString(), String... , , , ByteArray, , , ?

, , " Object", ? , ...

0

The class is final because you must not inherit it from NEED . The documentation shows that there are a ton of methods for geting and putfor all types of types. If you are really worried about converting Stringto byte[], then what you are looking for is a Java method ( click me ) and not something unique to Android.

0
source

All Articles