SoFunction
Updated on 2025-03-08

Android appears:...Error solution

Today, the test suddenly told me that I wrote the XX interface and it would crash!

Nani, I definitely don’t agree! How could it be that it crashes with just a click? It’s obviously my own test!

Then I tried it with my own test machine (Version:5.0.2), and then use crash to test the phone (Version:4.4) Good, it actually happened only in 4.4! (There is no verification below 4.4! Maybe it will all!!!)

log display:

 W/: : android/os/PersistableBundle
 W/:   at (Native Method)
 W/:   at (:656)
 W/:   at (:75)
 W/:   at (:163)
 W/:   at (:133)

Then of course it's Google!

*

Finally, the reason for this error was found:

 @Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
  (savedInstanceState, persistentState);
}
@Override
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
  (outState, outPersistentState);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
  (savedInstanceState);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
  (outState);
}

Note that when writing Activity, if you use the method of public two Bundle parameters, then crash will occur on the 4.4 machine!

As for the purpose of sacrificing, I haven't looked at it carefully. In essence, the two parameters are actually a method of taking one parameter. .

public void onCreate(@Nullable Bundle savedInstanceState,
    @Nullable PersistableBundle persistentState) {
  onCreate(savedInstanceState);
}

So don’t be careless when writing these callbacks, remember to rewrite the beginning of protected! ! !