Unexplainable ClassCastException in android.widget.ProgressBar.onRestoreInstanceState

后端 未结 7 1663
予麋鹿
予麋鹿 2020-12-29 19:21

I\'ve had my application out in the store for a while, but it seems it crashes occasionally according to the crash reports in the Developer Console, saying: java.lang.

7条回答
  •  无人及你
    2020-12-29 19:44

    I needed to use different layouts with same Id. So, the work around is

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        try {
            super.onRestoreInstanceState(savedInstanceState);
        } catch (Exception ignored) {
        }
    }
    

    This will save your application from crashing.

    super.onRestoreInstanceState(savedInstanceState) may be executed only till the point exception occurs. However, I don't find it useful, at least in my apps, so I can afford to bypass onRestoreInstanceState.

提交回复
热议问题