ClassNotFoundException: Didn't find class “android.os.PersistableBundle” Otto Android 5.0

感情迁移 提交于 2019-11-28 10:46:27

I find the "solution". Just remove this function from your activity :

@Override
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
    super.onSaveInstanceState(outState, outPersistentState);
}

Change targetVersion to the API version of the device you are running.

I had targetVersion = 21 when my device had 4.4 (API 19), changing the value to 19 solved the issue.

I had a same problem on Samsung Galaxy 3mini and Local operator phones.But i fixed with override activity method.i hope it works for you.

 @Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    try {
        BusApplication.getInstance().register(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Base on FAG

Some Android versions seem to have a bug with reflection when calling getDeclaredMethods or getMethods

in this case PersistableBundle was added in API level 21 and when we use it in lifecycle methods like onCreate or onSaveInstanceState this error happens.

If you use of any of following methods in your code

@Override
public void onCreate(Bundle savedInstanceState,PersistableBundle persistentState) {
    super.onCreate(savedInstanceState, persistentState);
}

@Override
public void onPostCreate(Bundle savedInstanceState,PersistableBundle persistentState) {
    super.onPostCreate(savedInstanceState, persistentState);
}

@Override
public void onRestoreInstanceState(Bundle savedInstanceState, PersistableBundle persistentState) {
    super.onRestoreInstanceState(savedInstanceState, persistentState);
}

@Override
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
    super.onSaveInstanceState(outState, outPersistentState);
}

Use following methods instead (or remove above methods if useless)

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Override
public void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
}

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
} 

In my case i use this method in baseActivity and made the crash

override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
        super.onCreate(savedInstanceState, persistentState) 
}

Simply i replace this with

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
}

And problem solved.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!