Coder Social home page Coder Social logo

Comments (5)

yingLanNull avatar yingLanNull commented on May 29, 2024

请问你的Activity里面做了有关Activity被回收后的状态保存之类的操作了吗?

from alphatabsindicator.

stormlei avatar stormlei commented on May 29, 2024

没有,只是重写了onRestoreInstanceState,随便打印了一句话,看看什么情况。后来我在super.onRestoreInstanceState(savedInstanceState); 上面调用alphaTabsIndicator.getTabView(0) 就没问题了,是不是isInit() 初始化的问题?

from alphatabsindicator.

wangkunlin avatar wangkunlin commented on May 29, 2024

我也遇到这个问题了 看了一下代码

// AlphaTabsIndicator.java
 /**
     * @return 当View被销毁的时候,保存数据
     */
    @Override
    protected Parcelable onSaveInstanceState() {
        Bundle bundle = new Bundle();
        bundle.putParcelable(STATE_INSTANCE, super.onSaveInstanceState());
        bundle.putInt(STATE_ITEM, mCurrentItem);
        return bundle;
    }

    /**
     * @param state 用于恢复数据使用
     */
    @Override
    protected void onRestoreInstanceState(Parcelable state) {
        if (state instanceof Bundle) {
            Bundle bundle = (Bundle) state;
            mCurrentItem = bundle.getInt(STATE_ITEM);
            if (null == mTabViews || mTabViews.isEmpty()) {
                super.onRestoreInstanceState(state); // 这里是第199行
                return;
            }
            //重置所有按钮状态
            resetState();
            //恢复点击的条目颜色
            mTabViews.get(mCurrentItem).setIconAlpha(1.0f);
            super.onRestoreInstanceState(bundle.getParcelable(STATE_INSTANCE));
        } else {
            super.onRestoreInstanceState(state);
        }
    }
// View.java
    protected void onRestoreInstanceState(Parcelable state) {
        mPrivateFlags |= PFLAG_SAVE_STATE_CALLED;
        if (state != null && !(state instanceof AbsSavedState)) {
            throw new IllegalArgumentException("Wrong state class, expecting View State but "
                    + "received " + state.getClass().toString() + " instead. This usually happens "
                    + "when two views of different type have the same id in the same hierarchy. "
                    + "This view's id is " + ViewDebug.resolveId(mContext, getId()) + ". Make sure "
                    + "other views do not use the same id.");
        }
        if (state != null && state instanceof BaseSavedState) {
            mStartActivityRequestWho = ((BaseSavedState) state).mStartActivityRequestWhoSaved;
        }
    }

我认为是 View 保存状态根本那就不能使用 Bundle 因为

public final class Bundle extends BaseBundle implements Cloneable, Parcelable {
    // ...
}
public static class BaseSavedState extends AbsSavedState {
    // ...
}
public abstract class AbsSavedState implements Parcelable {
    // ...
}

Bundle 根本就不是 AbsSavedState 或者 BaseSavedState 的子类,所以在 199 行调用 super.onRestoreInstanceState(state); 抛出了异常。

from alphatabsindicator.

yingLanNull avatar yingLanNull commented on May 29, 2024

谢谢@wangkunlin 提供的信息,由于我的疏忽,确实有类型方面的问题存在,已在新版修改了一个影响此问题的代码,请二位使用1.0.8测试。

from alphatabsindicator.

wangkunlin avatar wangkunlin commented on May 29, 2024

嗯,客气了。😊

from alphatabsindicator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.